jQuery .submit多次?

问题描述

| 我有以下代码:
$(\'.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/     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...