Jquery 表单 ajaxSubmit 未提交
我正在使用 JQuery Form 扩展通过 AJAX 提交表单。我有以下代码:
var options = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: 'post', // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
clearForm: true, // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
timeout: 3000
};
$('#composeForm').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).find(':disabled').removeAttr('disabled');
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
问题是表单似乎没有提交,或者至少没有调用成功函数。如果我删除 return false,则提交有效,但页面会导航离开。我的代码中是否存在可能导致此问题的问题?
干杯, 加兹勒。
编辑|似乎正在我的本地主机上工作。这可能与该域是附加域有关吗?
I am using the JQuery Form extension to submit a form with AJAX. I have the following code:
var options = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: 'post', // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
clearForm: true, // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
timeout: 3000
};
$('#composeForm').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).find(':disabled').removeAttr('disabled');
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
The problem is that the form doesn't appear to be submitting, or atleast the success function is not being called. If I remove the return false, then the submission works, but the page navigates away. Is there a problem in my code that could be causing this?
Cheers,
Gazler.
EDIT| Seems to be working on my localhost. Could it be something to do with the domain being an add-on domain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这里试试这个:
Here try this :
我的猜测是,当你删除 false 时,你的常规提交就会发生——在这两种情况下它根本不起作用。
我认为您需要为更多选项提供正确的值。那里评论了很多东西。另外,如果您只使用按钮来执行提交而不是表单提交,那么您不必担心尝试关闭浏览器所做的自动魔法功能,这可能会更好。
My guess is that when you remove the false your regular submit is happening -- it does not work at all in both cases.
I think you need to have the correct values for more of the options. There is a lot of stuff commented out there. Also, it might be better if you just use a button to do the submit and not a form submit, then you don't have to worry about trying to turn off the auto-magic stuff the browser does.
添加自己的解决方案,
iframe 选项需要是:
解决了问题。
感谢大家的意见。
Adding own solution,
The iframe option needed to be:
Which solved the problem.
Thanks to everyone for their input.
表单内会有一些字段经过验证,并且可能会隐藏,因此请检查所有字段并设置其验证,当我看到有一个隐藏字段由于 jQuery 隐藏显示而被隐藏时,它将对我起作用。或者您可以从表单中删除所有验证,它将起作用。
There will be some fields inside form that is validated and it may be hide so please check the all fields and set its validation it will work for me its work when i saw there was a hidden fields that is hide due to jQuery hide show. Or you can remove all validation from form it will work.