如何在AJAX事件结束之前暂停提交事件? [英] How to pause a submit event until an AJAX event finishes?
本文介绍了如何在AJAX事件结束之前暂停提交事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有表格和提交。如果有东西被填满,在提交之前我想确保它的价值很高(用ajax),如果是的话,那么我只能让它继续下去。所以,
I have a form and a submit. If something is filled, before submit I want to make sure its a good value (with ajax) and if so, THEN I can only let it continue. So,
$('#contact').submit(function() {
// ajax
$.ajax({
type: 'POST',
url: $(this).attr('ajaxgetaccommodationsbyemail'),
success: function(answer) {
here a popup window opens, which waits until I press YES or NO
},
async: false
});
this is when return TRUE or FALSE
there should be something like
do while (popupWindowClosed)
so $.when is not an option
});
推荐答案
您可以使用jQuery阻止提交,然后实际调用本机提交以发送表单
You can prevent the submit with jQuery, and then actually call the native submit to send the form
$('#contact').on('submit', function(e) {
e.preventDefault();
var form = this;
$.ajax({
type: 'POST',
url: $(this).attr('ajaxgetaccommodationsbyemail'),
success: function(answer) {
popup(function(yesorno) {
if (yesorno) {
form.submit();
}
});
}
});
});
并删除了 async:false
应 从不 执行同步ajax。
And the async:false
removed because you should never do syncronous ajax.
这篇关于如何在AJAX事件结束之前暂停提交事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文