1

したがって、次の単純なjavascript SOAPクライアントを実装しようとすると、このエラーが発生します。

Uncaught 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>
4

1 に答える 1

1

次の2行の前にバックラッシュがありません。

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

これにより、JavaScriptが失敗します。つまり、soap関数が定義されることはありません。

于 2013-03-02T22:47:00.697 に答える