0 Replies Latest reply on Aug 7, 2012 4:05 AM by Neal Phillips

    Why do I get readyState = 0 using $.ajax to call my web service ?

    Neal Phillips

      I'm attempting to call a pre-existing web service using JQuery, but it continually fails with a readyState of 0 and a status or 'error'

       

      The web service definitely works as I can call it using SoapUI, and I have had CORS enabled on the server.

       

      My code does not seem to reach or run the Success or statusError functions (although this could be because the code if failing ?)

       

      I'm new to JQuery so I'm hoping that this is a simple error to resolve.

       

      Thanks in Advance.

       

      The Code looks like this.

       

      
      <html>
       <head>
       <script src="jquery-1.7.2.js" type="text/javascript"></script>
       <script type="text/javascript">
      
      
       var url = "http://localhost:9080/SAA/endpoint";
      
      
       var soapEnv =
       "<soapenv:Envelope xmlns:soapenv='http:\\schemas.xmlsoap.org\soap\envelope\' xmlns:mes='http:\\messages.availabiltychecks.serviceagent.stockavailadmin.saa.anything.com'> \
          <soapenv:Header\> \
          <soapenv:Body> \
         <mes:findOutstandingChecksRequest> \
        <mes:findOutstandingChecksRequestMessage> \
       <mes:branchId>1</mes:branchId> \
       <mes:handsetId>handset1</mes:handsetId> \
       <mes:userId>me</mes:userId> \
       <mes:requestType>AVAILCHK</mes:requestType> \
        </mes:findOutstandingChecksRequestMessage> \
         </mes:findOutstandingChecksRequest> \
          <\soapenv:Body> \
       <\soapenv:Envelope>";
      
      
      
      
       function call()
       {
      
      
       $.ajax({
                 ServiceCallID: 1,
          url: url,
          type: "GET",
          data: soapEnv,
          dataType: 'xml',
                 contentType: "text/xml; charset=\"utf-8\"",
      
      
      
      
       success: function (result) {
       alert("Success");
       },
      
      
       complete: processResult,
      
      
       error: function (XMLHttpRequest, textStatus, errorThrown) {
       alert("error");
       }
      
      
      
      
       });
      
      
      
      
       };
      
      
      
      
       function processResult(xData, status)
       {
       alert("Process Result - data loaded: " + xData.toStringify);
       document.getElementById('readyState').innerHTML = xData.readyState;
       document.getElementById('status').innerHTML = xData.statusText;
       }
      
      
      
      
       </script>
      
      
       </head>
       <body>
       <h1>Demo </h1>
      
      
       <div>Scanned Item: <span id="itemName"></span></div>
       <div>Ready State : <span id="readyState"></span></div>
       <div>Status      : <span id="status"></span></div>
       <br/>
       <button type="button" onclick="call()">Request Data</button>
       <br/>
       <br/>
      
      
       </body>
      </html>