jQuery submit form without reloading page

佐手、 提交于 2019-11-30 18:34:56

Rather than bind to the click event (input[type=submit]) you should bind to the submit event for the form.

$("form").on("submit", function (e) {
    e.preventDefault();

I'm also not sure about the validation. If it runs asynchronously, a callback is required. If it runs synchronously, when does it get triggered? It seems like it should be done when the form is submitted unless your validation plugin does that on its own:

$("form").on("submit", function (e) {
    e.preventDefault();
    if ($(this).validate(options)) {
        $.ajax

Using e.preventDefault will prevent reload and should allow your success div to display.

1) Use event.preventDefault(); to keep the form from submitting -http://api.jquery.com/event.preventDefault/

2) There isn't anything in the given script that should be causing #result to hide, but you can try $('#result').show() and see if that brings it back

Jay Patel

Please check which jQuery version you are using because in after jQuery 1.8.2 "success" function from jQuery Ajax is deprecated.

Use e.preventDefault() to prevent actual submit event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!