我正在开发phonegap应用程序。我需要通过 .net webservice 验证用户。我正在使用 ajax 通过 javascript 验证和解析它。但我被困在 readystate ,因为它总是返回零。我从网上找到的可用解决方案中尝试了很多东西,但我没有做对。
这是我的Javascript:
username = 'ksl';
password = 'ksl';
var soapMessage =
'<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> \
<CheckLogin xmlns="http://tempuri.org/"> \
<UserName>' + username + '</UserName> \
<Password>' + password + '</Password> \
</CheckLogin> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: validationURL,
type: "POST",
dataType: "xml",
data: soapMessage,
success: validate,
contentType: "text/xml; charset=\"utf-8\"",
error: function(xhr,status,error)
{
alert("state is:" + xhr.readyState);
}
});
return false;
这是我的网络服务响应:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<CheckLoginResponse xmlns="http://tempuri.org/">
<CheckLoginResult>string</CheckLoginResult>
</CheckLoginResponse>
</soap:Body>
</soap:Envelope>
任何回应都会有所帮助