問題是,在登錄頁面上,提交不正確的條目後,ajax請求在按提交後不會再次執行。使用jquery的登錄頁面不會重新提交
我已經通過StackExchange搜尋了我的問題的答案,並查看了其他12個鏈接,如Why won't my jQuery form resubmit?和jQuery & AJAX login form。看起來我需要解除綁定提交的變量,但不知道如何做到這一點。
HTML
<div data-role="page" id="login">
<div data-role="header" data-position="inline" data-theme="b">
<h1>My login</h1>
</div><!-- /header -->
<div data-role="content">
<form method="post" id="loginform">
<label for="username">Username:</label> <input type="text" name="username" id="username" value="" />
<label for="passwd">Password:</label> <input type="password" name="passwd" id="passwd" value="" />
<input type="submit" value="Login" />
</form>
</div><!-- /content -->
</div><!-- /login page -->
的JavaScript:
$(document).ready(function() {
$("#loginform").on('submit',function(event){
var $form = $(this),
serializedData = $form.serialize();
// fire off the request to /form.py
$.ajax({
url: "https://mywebsite/cgi-bin/form.py",
type: "post",
data: serializedData,
// callback handler that will be called on success
success: function(response, textStatus, jqXHR){
console.log(response);
// If login is unsuccessful, log message and return to login screen again
if (response == "INVALID_USER\n") {
alert("sorry, try again");
} else {
// Login successful - do something
}
},
// callback handler that will be called on error
error: function(jqXHR, textStatus, errorThrown){
console.log(
"The following error occured: "+
textStatus, errorThrown);
},
// callback handler that will be called on completion
// which means, either on success or error
complete: function(){
//----- DO I NEED TO UNBIND SOMETHING HERE?
var dummy = 1;
}
}); // end of ajax call
}); // end of submit handler
});
你把警報在javascript中進行調試嗎?哪裏有問題? – pkachhia
是的警報是有調試。問題是,如果登錄失敗,我重新提交表單,它不起作用 - 服務器請求永遠不會通過。 –
好的告訴我一件事,就是你的頁面通過cgi顯示嗎?你是否通過任何主板運行你的頁面? – pkachhia