问题描述
|
我有以下代码:
$(\'.save\').submit(function(e){
var data = \'id=\' + $(this).attr(\'name\') + \'&\' + $(this).serialize();
var messageBox = $(this).next(\'.message\');
messageBox.html(\'<div class=\"pending\">Saving... please wait...</div>\');
$.post(\'save.php\',data,function(response) {
messageBox.html(response).delay(3000).fadeOut(\'slow\');
});
e.preventDefault();
});
而且效果很好,但是,当用户再次按下\“ save \”时,似乎ѭ1不再被触发。...我至少没有在messageBox
中看到待处理或成功消息。
我想念什么?
编辑
我想到了。当我fadeOut
时,我不会淡出错误div,而是正在淡化整个messageBox
div,所以一旦once5ѭ,就没有任何东西可以将其恢复。
解决方法
最可能的问题是您的AJAX无法成功返回。向其添加一个.error()函数。
来自jQuery文档的示例代码:
// Assign handlers immediately after making the request,// and remember the jqxhr object for this request
var jqxhr = $.post(\"example.php\",function() {
alert(\"success\");
})
.success(function() { alert(\"second success\"); })
.error(function() { alert(\"error\"); })
.complete(function() { alert(\"complete\"); });
// perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function(){ alert(\"second complete\"); });
http://api.jquery.com/jQuery.post/