1

因此,在尝试实现以下简单的 javascript SOAP 客户端时,我遇到了这个错误:

未捕获的 ReferenceError:未定义肥皂 soaptest.html:60

onclick soaptest.html:60

这是客户端:

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap()
         {
            $(document).ready(function () {
                $("#send").click(function (event) {
                    var wsUrl = "http://redactedurl.redactedurl.com/c";

                    var soapRequest =
                    '<?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> \
                    <getApiFunction xmlns="http://tempuri.org/">
                        <zipCode>10032</zipCode>
                        <series>avalon</series>\
                    </getApiFunction> \
                    </soap:Body> \
                    </soap:Envelope>';

            console.log(soapRequest);

            $.ajax({
                type: "post",
                url: wsUrl,
                contentType: "text/xml",
                dataType: "xml",
                data: soapRequest,
                success: processSuccess,
                error: processError
            });

            });
        });
    }

    function processSuccess(data, status, req, xml, xmlHttpRequest, responseXML) {
        $(req.responseXML)
        .find('XMLNode')
        .each(function(){
            var id = $(this).find('xmlchildnode').text();
            console.log(id);
        });
    }

    function processError(data, status, req) {
        alert(req.responseText + " " + status);
        console.log(data);
        console.log(status);
        console.log(req);
    }   
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
<html>

这是我第一次尝试使用 AJAX,所以我敢肯定有很多错误......任何帮助将不胜感激。这是 SOAP 请求(如果有必要)

POST /apiname.asmx HTTP/1.1
Host: redactedurl.redactedurl.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/getApiFunction"

<?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>
    <getApiFunction xmlns="http://tempuri.org/">
      <zipCode>string</zipCode>
      <series>string</series>
    </getApiFunction>
  </soap:Body>
</soap:Envelope>
4

1 回答 1

1

您在这两行之前缺少强烈反对:

<getApiFunction xmlns="http://tempuri.org/">
<zipCode>10032</zipCode>

这会导致您的 javascript 失败,这意味着您的soap函数永远不会被定义。

于 2013-03-02T22:47:00.697 回答