jquery.ajax readystate 0,status 0

时间:2011-05-23 09:39:38

标签: jquery ajax

我正在调用.net xml webservice。我正在调用的web方法是“validatePassword” 我不确定我在这里做错了什么。我仍然是jquery和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响应。

<?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>

1 个答案:

答案 0 :(得分:0)

您的XML属性使用单引号而不是双引号。

<强>错

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

从右

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