0
我正在開發phonegap應用程序。我需要通過.net webservice驗證用戶。我使用ajax來驗證和解析它通過javascript.but我卡在readystate,因爲它總是返回零。我從網上找到的可用解決方案中嘗試了很多東西,但是我不明白。Readystate始終爲0
這裏是我的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;
,這裏是我的web服務響應:
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>
任何迴應,將有助於
這是一個跨域請求? – Niko 2012-04-21 09:47:19
對不起,因爲我的無知與JavaScript和ajax ..有關,但在這裏我使用的是使用javascript和ajax的m的phonegap。 webservice來自.net ..它跨域? – dreamcoder 2012-04-21 09:53:20
我沒有使用phonegap的經驗,但在正常的Web瀏覽器中,您不允許向另一個主機發送ajax請求 - 這是我首先想到的,因爲您經常看到請求在readystate 0中死亡,因爲這樣跨域策略。 – Niko 2012-04-21 09:57:43