簡體   English   中英

未識別功能javascript / ajax soap客戶端

[英]function not identified javascript/ajax soap client

因此,在嘗試實現以下簡單的JavaScript SOAP客戶端時,我遇到了此錯誤:

未被捕獲的ReferenceError:soap未定義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>

您會在這兩行前面缺少反彈:

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

這導致您的javascript失敗,這意味着您的soap函數永遠不會得到定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM