jQuery Mobile 1.3.1 & jQuery JavaScript Library v1.9.1 を使用して PhoneGap アプリケーションを開発しています。ユーザー名とパスワードを使用したログインフォームがあります。ログインを処理するための JSON データを送受信できる JSON API があります。
ajax ログインには次の JavaScript を使用します。
$('#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>
しかし、これはうまくいきません。サーバーはログイン失敗エラーを返しますが、他のアプリでは正常に機能します。