本文介绍了如何使用 Jquery 在页面加载时触发表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这看起来应该不太难,但我很着急,一直在寻找一个简单的答案.我需要在页面加载时提交表单.这是我的 AJAX 提交功能,工作正常.我只需要弄清楚如何在页面加载时触发它.
This doesn't seem like it should be too difficult to accomplish, but I'm in a rush and I have been looking for a simple answer. I need to submit a form on page load. This is my AJAX submit function which works fine. I just need to figure out how to trigger it on page load.
非常感谢任何帮助!
$("form#seller-agreement-form").submit(function() {
// we want to store the values from the form input box, then send via ajax below
$.ajax({
type: "POST",
url: "http://www2.myurl.com/formhandler",
data: "email="+ email + "&status=" + status,
success: function(){
$('form#seller-agreement-form').hide(function(){$('div#output').fadeIn();});
}
});
return false;
});
推荐答案
如果你调用 $().submit()
它会触发动作;$().submit(function)
将处理程序绑定到提交事件.
if you call $().submit()
it triggers the action; $().submit(function)
binds a handler to the submit event.
不过你可以跳过提交,直接调用ajax方法.
You can skip the submit however and just call the ajax method directly.
$(function() {
$.ajax({
type: "POST",
url: "http://www2.myurl.com/formhandler",
data: "email="+ email + "&status=" + status,
success: function(){
$('form#seller-agreement-form').hide(function(){$('div#output').fadeIn();});
}
});
});
这篇关于如何使用 Jquery 在页面加载时触发表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!