说我们有
$submitButton.click(function(e){
doSomething(e);
return false;
});其中$submitButton是表单提交按钮的jQuery对象。假设doSomething是一个带有AJAX调用的异步方法。
如果我是return true,那么表单是在doSomething结束之前提交的,所以我想要提交return false,然后一旦doSomething结束AJAX,在成功回调中,我想实际上提交表单。
这可以只使用e吗?多么?
发布于 2018-05-22 17:07:26
$submitButton.click(function(e){
//make doSomething return a promise that you can chain off of
doSomething(e).then(function(){
//submit the parent form
$submitButton.closest('form').trigger('submit');
});
//cancel the click and wait for the ajax to finish
return false;
});https://stackoverflow.com/questions/50473033
复制相似问题