shuxx

导航

javascript 请求web service

<script language="javascript">
    var strXMl
    strXMl='<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> '+
        '<soap:Body>' +
        '<HelloWorldXML xmlns="http://Excellence.Form/">'+
        '<strValue>测试吗</strValue> '+
        '</HelloWorldXML>' +
        '</soap:Body>' +
        '</soap:Envelope>'


    alert( sendHttpRequest("/GetWebForm/GetWebForm.asmx", "HelloWorldXML", strXMl));
    function sendHttpRequest(strURl,FuncName ,strXMl) {
        var XMLHttp = null;
        try {
            XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                XMLHttp = new XMLHttpRequest();
            }
        }
        if (XMLHttp == null) {
            alert('请检查是否正确的安装XML组件,如有问题请与管理员联系!');
            return (null);
        }
        else {
            XMLHttp.Open("POST", strURl   , false);
            XMLHttp.setRequestHeader("SOAPAction", "http://Excellence.Form/" + FuncName);
            XMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
          //  XMLHttp.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            XMLHttp.setRequestHeader("Content-Length", strXMl.length);
            XMLHttp.send(strXMl);
            var resultXml = XMLHttp.responseText;
            if (XMLHttp.readyState == 4) {
                // 收到完整的服务器响应
                if (XMLHttp.status == 200) {

                    return (XMLHttp.responseText);
                }
                else {
                    alert('XML请求发生了错误' + XMLHttp.status + XMLHttp.responseText);
                    return (null);
                }
            }
        }   
  }
</script> 

posted on 2009-03-11 11:30  舒秀宣  阅读(387)  评论(0编辑  收藏  举报