2013-03-02 46 views
1

所以在試圖實現以下簡單的JavaScript SOAP客戶端,我遇到了這個錯誤:功能沒有確定的JavaScript/AJAX SOAP客戶端

Uncaught ReferenceError: soap is not defined 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> 

回答

1

你錯過了在這兩行前的反彈:

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

這是造成你的JavaScript失敗,這意味着你的功能永遠不會被定義。