我正在调用 .net xml 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>
最佳答案
您的 XML 属性使用单引号而不是双引号。
错误
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
右
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
关于jquery.ajax 就绪状态 0,状态 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095419/