0

我正在尝试使用 JavaScript 使用 SOAP (.net) WebService,但 responseText 和 responseXML 为空。我尝试在另一个浏览器(chrome、firefox、IE)中运行,但这并没有解决它。

function MButton1Click(event) {
    sendDataAsXML_SOAP();
}


function sendDataAsXML_SOAP() {
    var req_params = "",
        url = "",
        number = 0,
        type = "";
    /* Configure Parameters */
    url = "http://wp.art.br/FriendNet/Principal.asmx";
    var user = document.getElementById("MTextArea1").value;
    var ajaxRequest;
    req_params = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    req_params = req_params + "<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/\">";
    req_params = req_params + "  <soap:Body>";
    req_params = req_params + "    <TesteDeTexto xmlns=\"http://tempuri.org/\">";
    req_params = req_params + "      <pTexto>" + user + "</pTexto>";
    req_params = req_params + "    </TesteDeTexto>";
    req_params = req_params + "  </soap:Body>";
    req_params = req_params + "</soap:Envelope>";
    /* Send XML/SOAP Request To Web Service Using Browser's Javascript DOM */
    var xmlHTTP;
    if (window.XMLHttpRequest) {
        xmlHTTP = new window.XMLHttpRequest; //For browsers other than ie
    } else {
        try {
            xmlHTTP = new ActiveXObject("MSXML2.XMLHTTP.3.0"); //for ie
        } catch (ex) {}
    }
    xmlHTTP.open("POST", url, true);
    xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHTTP.setRequestHeader("SOAPAction", "http://tempuri.org/TesteDeTexto");
    xmlHTTP.onreadystatechange = receiveXML_SOAPData;
    xmlHTTP.send(req_params);
}

function receiveXML_SOAPData() {
    if (ajax_request.readyState == 4) {
        if (ajax_request.status == 200 || ajax_request.status == 0) {
            /* Parse The Response Data */
            alert(ajax_request.responseText);
            alert(ajax_request.responseXML);
            alert("sucesso");
        }
    }
}
4

1 回答 1

0

您尝试ajax_request在您的receiveXML_SOAPData函数中使用 a undefined。你应该得到一个例外,检查你的错误控制台。

函数中的ajaxrequest变量sendDataAsXML_SOAP是 a) 未使用和 b) 该函数的局部变量 - 它不起作用。

改用函数中的this关键字receiveXML_SOAPData来引用 XHR 对象。

于 2012-09-14T14:48:52.130 回答