【发布时间】:2015-04-27 08:36:35
【问题描述】:
您好,我目前在触发 .ajaxComplete 函数时遇到问题,它应该在演示站点上运行。我从这里引用这个函数http://www.bitrepository.com/a-simple-ajax-username-availability-checker.html
这是我的代码:
<SCRIPT type="text/javascript">
<!--
/*
Credits: Bit Repository
Source: http://www.bitrepository.com/web-programming/ajax/username-checker.html
*/
pic1 = new Image(16, 16);
pic1.src = "loader.gif";
$(document).ready(function(){
$("#userID").change(function() {
var usr = $("#userID").val();
if(usr.length >= 4)
{
$("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "check.php",
data: "userID="+ usr,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == "OK")
{
$("#userID").removeClass('object_error'); // if necessary
$("#userID").addClass("object_ok");
$(this).html(' <img src="tick.gif" align="absmiddle">');
}
else
{
$("#userID").removeClass('object_ok'); // if necessary
$("#userID").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
$("#userID").removeClass('object_ok'); // if necessary
$("#userID").addClass("object_error");
}
});
});
//-->
</SCRIPT>
我曾尝试提醒 msg,check.php 能够返回 msg 值,但它在 .ajaxComplete() 处停止,在那里它不会在 .ajaxComplete() 之后触发该函数。请指导我完成这个。谢谢
【问题讨论】:
-
查看文档 - api.jquery.com/ajaxcomplete -
As of jQuery 1.8, the .ajaxComplete() method should only be attached to document. -
@ArunPJohny 是什么意思?对不起我的英语不好。
标签: javascript ajax