继p
revious question后,我询问禁用提交按钮,直到所有ajax调用完成返回…
即使禁用按钮和警告标志,人们似乎仍然设法提交表单.我想这可能是在文本输入中按“输入”.
如何禁用整个表单,而不仅仅是提交按钮?
到目前为止的代码是:
// if we're waiting for any ajax to complete we need to disable the submit
$(document).ajaxStart(function() {
$(".ajaxbutton").attr("disabled","disabled");
// if it's taken longer than 250ms display waiting message
timer = setTimeout(function() {
$('#processingAlert').html(' ...please wait one moment');
$('#processingAlert').show();
},250);
})
$(document).ajaxComplete(function() {
$(".ajaxbutton").removeAttr("disabled");
$('#processingAlert').hide();
// cancel showing the message when the ajax call completes.
clearTimeout(timer);
});
我应该提到的另一个可能导致问题的是,同时发生多个ajax调用,EG一个div接收隐藏的输入,另一个div在页面的其他地方显示例如价格总和.
一些ajax调用快速完成的事实是否会否定ajaxStart的禁用效果? EG ajax call1和ajax call2都触发了ajaxStart – call1很快就完成了,在我们等待call2完成时它会重新启用表单吗?
有没有更好的方法来做到这一点我们可以简单地测试所有ajax调用是否已经完成?