jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery-mobile – jQuery Mobile中的AJAX表单提交大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在jQuery Mobile网站上通过ajax提交一个简单的@L_944_1@表单,但我遇到了麻烦.

看来,当我提交表单(通过POST)时,表单参数会被添加到url中.不仅如此,他们还删除了表单提交前我所处的锚定页面.

例如,我在localhost:8080 / myapp /#sign_up页面

然后我提交表单,使url成为:localhost:8080 / myapp /?email=a@a.com\u0026amp; pass = pass

因此,如果我点击验证错误并单击“后退”按钮,我就不会返回到#sign_up页面.

有任何想法吗?

解决方法

如果您使用自定义提交事件处理程序处理表单提交,则可以在同一页面上处理验证:
//bind an event handler to the submit event for your login form
$(document).on('submit','#form_id',function (E) {

    //cache the form element for use in this function
    var $this = $(this);

    //prevent the default submission of the form
    e.preventDefault();

    //run an AJAX post request to your server-side script,$this.serialize() is the data from your form being added to the request
    $.post($this.attr('action'),$this.serialize(),function (responseData) {

        //in here you can analyze the output from your server-side script (responseData) and validate the user's login without leaving the page
    });
});

要阻止jQuery Mobile运行自己的表单的AJAX sumbission,请将其放在表单标记上:

<form data-ajax="false" action="...">

大佬总结

以上是大佬教程为你收集整理的jquery-mobile – jQuery Mobile中的AJAX表单提交全部内容,希望文章能够帮你解决jquery-mobile – jQuery Mobile中的AJAX表单提交所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。