xmlHttpRequest.open("GET","hello.hello",true);  
hello.hello 是什么?url?
         
xmlHttpRequest.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8");
这个头将会破坏服务端对传入数据的解析
 
xmlHttpRequest.send(xmlDocI);
只有 post 方式才会发送参数,get 方式是不会发送的

解决方案 »

  1.   

    xmlDoc.async=false;
      xmlDoc.load(url);
      return(xmlDoc);你直接返回xmldom,ajax的send方法是不会自动序列化为xml字符串的,会调用toString方法返回对象名称,你要自己序列化为xml字符串
    if(xmlDoc.xml)return xmlDoc.xml;//IE
    if(window.XMLSerializer)return new window.XMLSerializer().serializeToString(xmlDoc);
    alert('无法序列化xmldom');
      

  2.   

    感谢showbo  showbo 回复。
    hello.hello 是我自己定义的,服务那边可以识别。问题还没有解决,麻烦两位版主再指导指导!
    xmlDocI=loadXMLDoc(url);
    str=XML2String(xmlDocI);
            document.getElementById("a").innerHTML=str;//convert xml object to string
    function XML2String(xmlObject)
    {
    // for IE
    if (window.ActiveXObject)
    {
    return xmlObject.xml;
    }
    // for other browsers
    else 
    {
    return (new XMLSerializer()).serializeToString(xmlObject);
    }
    } 以上程序显示str为: 1.0 3.0  。 这并不是我预期的结果,我希望通过
    xmlHttpRequest.send(str)把calc.add.req.xml数据作为http content发送出去。另外,我调用  xmlHttpRequest.send("hello world!"), 也没有发现"hello world!"被发送出去!! 哪里的问题呢?? 
     
    calc.add.req.xml文件如下:<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
      xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:ns2="urn:calc">
     <SOAP-ENV:Body  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <ns2:add>
       <a>1.0</a>
       <b>3.0</b>
      </ns2:add>
     </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
      

  3.   

    正解:xmlHttpRequest.send(xmlDocI);
    只有 post 方式才会发送参数,get 方式是不会发送的
      

  4.   

    send发送的数据,open时要指定为post,并且设置content-type请求头,而且你确认你的程序需要的是xml字符串内容,而不是键值对形式的数据?你直接发送xml字符串没有指定键值对格式服务器端获取数据是不能通过request.form/request.querystring这种对象的document.getElementById("a").innerHTML=str;,这样设置容器,html标签是不会显示的    function ParseLoadXMLDoc(url) {
            xmlDocI = loadXMLDoc(url);        xmlHttpRequest = createXmlHttpRequest();        xmlHttpRequest.onreadystatechange = get_result;        xmlHttpRequest.open("POST", "hello.hello", true);//////////        xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");///////        xmlHttpRequest.send(xmlDocI);
        }    function get_result() {
            if (xmlHttpRequest.readyState == 4) {
                if (xmlHttpRequest.status == 200) {
                    var response = xmlhttp.responseText;
                    document.getElementById("result").innerHTML = response;
                }
            }
        }
        function XML2String(xmlObject) {
            // for IE
            if (window.ActiveXObject) {
                return xmlObject.xml;
            }
            // for other browsers
            else {
                return (new XMLSerializer()).serializeToString(xmlObject);
            }
        } 

        function loadXMLDoc(url) {
            var xmlDoc;
            try {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            }
            catch (e) {
                try {
                    xmlDoc = document.implementation.createDocument("", "", null);
                }
                catch (e) { alert(e.message) }
            }
            try {
                xmlDoc.async = false;
                xmlDoc.load(url);
    alert(XML2String(xmlDoc))///////////
                return XML2String(xmlDoc);/////////////////////////////////

            }
            catch (e) { alert(e.message) }
            return (null);
        }