简体   繁体   English

如何在不重新加载页面的情况下提交表单数据

[英]How to submit a form data without reloading the page

I tried submitting form data without reloading the page using a submit event check.我尝试使用提交事件检查提交表单数据而不重新加载页面。 Below is my piece of code:下面是我的一段代码:

$( "#my-form" ).submit(function( event ) {
            alert( "Handler for .submit() called." );
            //event.preventDefault();
            return false;
                });

Due to this page refresh has been stopped.由于此页面刷新已停止。 But the action mapping to the form is not getting called.但是没有调用映射到表单的操作。 Is there any way that I can call the action and submit data without reloading page.有什么方法可以调用操作并提交数据而无需重新加载页面。

In the submit handler you have to make an ajax call that serializes the form data and sends it over.在提交处理程序中,您必须进行一个 ajax 调用来序列化表单数据并将其发送过去。 Adding event.preventDefault() and return false avoid the page refresh添加event.preventDefault()return false避免页面刷新

See this Submit form via AJAX in jQuery 在 jQuery 中通过 AJAX查看此提交表单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM