我将jquery更新为旧文件中的新版本,该文件添加了一些新功能。现在jquery ajax帖子已停止工作了。我已经尝试过改变成功,但这并没有解决问题。
// check email in database
$("#email_address").change(function () //this function needs tidying up!
{ //if theres a change in the email textbox
var email_address = $("#email_address").val(); //Get the value in the username textbox
if (email_address.length > 3) //if the lenght greater than 3 characters
{
$("#availability_status").html('<img src="../img/loader.gif" align="absmiddle"> Checking this email is not already registered<br />'); //Add a loading image in the span id="availability_status"
$.ajax({ //Make the Ajax Request
type: "POST",
url: "../ajax_check_email.php", //file name
data: "email_address=" + email_address, //data
success: function (server_response) {
$("#availability_status").ajaxComplete(function (event, request) {
if (server_response == '0') //if ajax_check_email.php return value "0"
{
$("#availability_status").css("display", "none");
} else if (server_response == '1') //if it returns "1"
{
$("#availability_status").css("display", "inline");
$("#availability_status").html('<font color="red">This email address is already registered in our database. </font>');
}
});
}
});
}
return false;
});
答案 0 :(得分:1)
我猜这是:
http://api.jquery.com/ajaxComplete/:
&#34;从jQuery 1.8开始,.ajaxComplete()方法只应附加到文档。&#34;
但是,我不确定为什么会这样开始。您应该可以完全删除ajaxComplete
部分:
success: function (server_response) {
if (server_response == '0') //if ajax_check_email.php return value "0"
{
$("#availability_status").css("display", "none");
} else if (server_response == '1') //if it returns "1"
{
$("#availability_status").css("display", "inline");
$("#availability_status").html('<font color="red">This email address is already registered in our database. </font>');
}
}
答案 1 :(得分:0)
应该足够了:
$( document ).ajaxComplete(
答案 2 :(得分:0)
从jQuery 1.8开始,.ajaxComplete()
方法只应附加到文档,例如:
$(document).ajaxComplete(function() {
// do something on complete
});
请参阅documentation。
您的AJAX请求中有一个ajaxComplete()
方法。您是否可以像complete()
回调一样使用success()
回调?
$.ajax({
type: "POST",
url: "../ajax_check_email.php", //file name
data: "email_address=" + email_address, //data
success: function() {
// do something
},
complete: function() {
// do something
}
});