jQuery Mobile 中的 AJAX 表单提交
我正在尝试通过 ajax 在 jQuery Mobile 网站上提交一个简单的登录表单,但遇到了麻烦。
似乎当我提交表单(通过 POST)时,表单参数被添加到 url 中。不仅如此,他们还删除了我在提交表单之前所在的锚定页面。
例如,我在页面 localhost:8080/myapp/#sign_up
然后我提交表单,导致 url 变为: localhost:8080/myapp/[电子邮件受保护]&pass=pass
因此,如果我遇到验证错误并单击“后退”按钮,我不会返回到 <代码>#sign_up 页面。
有什么想法吗?
I'm trying to submit a simple login form via ajax on a jQuery Mobile site but I'm having trouble.
It seems that when I submit the form (via POST), the form parameters are getting added to the url. Not only that, they erase the anchored page I was at before form submission.
For example, I'm on page localhost:8080/myapp/#sign_up
Then I submit the form causing the url to become: localhost:8080/myapp/[email protected]&pass=pass
So if I hit validation errors and click a 'back' button, I don't get returned back to the #sign_up
page.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用自定义
submit
事件处理程序处理表单提交,则可以在同一页面上处理验证:要阻止 jQuery Mobile 运行其自己的表单 AJAX 提交,请将其放在表单标记上:
If you handle form submission with a custom
submit
event handler you can handle validation on the same page:To stop jQuery Mobile from running its own AJAX sumbission of your form put this on your form tag:
上面的 Jaspers 解决方案对我有用!我唯一需要调整的是将 .live 替换为 .submit (.live 现已弃用)。所以现在是这样的:
Jaspers solution above worked for me! The only thing I had to adjust was replacing .live with .submit (.live is now deprecated). So now its like this:
如果您想提交表单而不使用 ajax(默认),则必须将 'data-ajax="false"' 添加到表单字符串中:
If you want to submit a form and not use ajax (which is default) you must add 'data-ajax="false"' to your form string: