私の質問は次のとおりです。
jqueryモバイルアプリケーションのログインを作成しています。私はこれを標準のhtmlログインフォームで行っています。送信ボタンをクリックした後、提供されたユーザー名とパスワードが正しいかどうかを確認しています。Ajaxとjsonを使ってこれをチェックします。私が次のことをすると、問題は次のようになります:
function authenticate(userName, password1) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: "http://notgiven",
dataType: 'json',
async: false,
//json object to sent to the authentication url
//data: {"username": "' + userName + '", "password" : "' + password + '"},
data: { username: "user1", password: "test1" },,
success: function (data) {
//do any process for successful authentication here
alert('Login status: ' + data.status);
}
})
};
それから私は成功します、
しかし、フィールドからパラメーターを取得してこれを実行したい場合は、次のようにします。
$(document).ready(function() {
//event handler for submit button
$("#btnSubmit").click(function () {
//collect userName and password entered by users
var userName = $("#username").val();
var password = $("#password").val();
});
});
function authenticate(userName, password1) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: "http://notgiven",
dataType: 'json',
async: false,
//json object to sent to the authentication url
//data: '{"username": "' + userName + '", "password" : "' + password + '"}',
data: '{username: userName, password: password1 }',
success: function (data) {
//do any process for successful authentication here
alert('Login status: ' + data.status);
}
})
};
それから私は失敗します...誰もが理由を知っていますか?
答え:*答え:*回答:*回答: *
私は入れました:authenticate(userName、password); Thrustmasterが言ったようにクリック機能に。アンドリューが言ったように、クリック中のユーザー名とパスワードのデータが範囲外になるため、これを行います。
また、returnfalseを設定しました。.click関数で、ボタンを複数回クリックできるようにします(そして、関数認証の結果を取得します)。
THNX