简体   繁体   中英

jquery.ajax readystate 0, status 0

I'm calling a .net xml webservice. the web method im calling is "validatePassword" I'm not sure what i'm doing wrong here. I'm still very new the jquery and ajax.

 var name = $("#name",$("#loginPage")).val();
    var password = $("#password",$("#loginPage")).val();
    var ServiceUrl = "http://localhost:52146/SmartMeterMobile_WebService/User.asmx";    
     var soapEnv ="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\
                        <soapenv:Body> \
                         <validatePassword xmlns='http://tempuri.org/'>\
                <UserName>"+name+"</UserName>\
                <Password>"+password+"</Password>\
            </validatePassword>\
            </soapenv:Body> \
                </soapenv:Envelope>";

            $.ajax({
                url: ServiceUrl,
                type: "POST",
                dataType: "xml",
                data: soapEnv,
                complete: processResult,
                contentType: "text/xml; charset=\"utf-8\""
            });


function processResult(xData, status) {

            $(xData.responseXML).find("NewDataSet").each(function() {
               alert($(this).find("intUserIdUS"))
            });
        }

xml response.

<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://tempuri.org/">
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="tblData">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="intUserIdUS" type="xs:int" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <NewDataSet xmlns="">
      <tblData diffgr:id="tblData1" msdata:rowOrder="0">
        <intUserIdUS>1</intUserIdUS>
      </tblData>
    </NewDataSet>
  </diffgr:diffgram>
</DataSet>

Your XML attributes have single quotes instead of double quotes.

wrong

<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>

right

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM