我正在開發使用jQuery移動1.3.1 & jQuery JavaScript庫v1.9.1的一個PhoneGap的應用程序。我有一個用戶名和密碼的登錄表單。有一個JSON API可以發送和接收JSON數據來處理登錄。發送和接收JSON數據| PhoneGap的+ jQuery Mobile的使用應用AJAX()
我用下面的JavaScript的Ajax登陸。
$('#submit').bind('click', function(e) {
e.preventDefault();
$.ajax({
type : "POST",
url : "http://domainx/public/login",
xhrFields : {withCredentials: true},
crossDomain: true,
beforeSend : function() {$.mobile.showPageLoadingMsg();},
complete : function() {$.mobile.hidePageLoadingMsg();},
data : {username : 'subin', password : 'passwordx'},
dataType : 'json',
success : function(response) {
console.error(JSON.stringify(response));
},
error : function() {
console.error("error");
}
});
});
這是我的登錄表單的html代碼。
<div data-role="content">
<form id="login-form" data-ajax="false" method="post">
<fieldset>
<input type="text" name="username" id="username" value="subin" placeholder="Username">
<input type="password" name="password" id="password" value="passwordx" placeholder="Password">
<input type="button" data-theme="b" name="submit" id="submit" value="Enter" data-icon="plus">
</fieldset>
</form>
</div>
但這只是行不通的。服務器返回登錄失敗錯誤,但它對其他應用程序正常工作。
你解決this.I得到了相同的error.Cant解決問題,這些問題的答案 – Sunny
@Sunny IIRC,我的問題是與服務器端。請閱讀已接受的答案及其評論。 –
其在郵差的工作。但不是在PhoneGap的應用錯字注 – Sunny