没有任何操作的 Safari Chrome 表单无法正常工作

发布于 2024-10-06 09:28:11 字数 222 浏览 0 评论 0原文

我正在使用 Django 和 jQuery 构建一个应用程序。对于 HTML 中的某些表单,我仅使用 jQuery 进行 AJAX 调用,因此我将表单与 action="#" method="" 放在一起。

当我按下 FF 中的提交按钮时,它工作正常,没有重新加载任何内容,并且进行了 ajax 调用。然而,在 Chrome 和 Safari 中,页面会重新加载并从服务器重新请求。

有什么线索吗?

I'm building an app using Django and jQuery. For in some forms in the HTML I make AJAX calls using only jQuery so I put the form with action="#" method="" and have.

When I press the submit button in FF it works fine, nothing gets reloaded and the ajax call is made. In Chrome and Safari, however, the page get's reloaded and re-requested from the server.

Any clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2024-10-13 09:28:11

Webkit 和 Opera 尝试尽可能遵循 HTML5 草案。目前,表单提交部分表示以 HTTP(S) 开头的操作,即使是 action="#"action="",也会导致导航,当添加新的 GET 参数时,这应该会导致新页面加载。如果您想阻止页面重新加载,则必须添加一个提交处理程序,通过返回 false 或显示 e.preventDefault() 来阻止默认操作。

As much as possible, Webkit and Opera try to follow the HTML5 draft. Currently, the form submission section says that actions that start with HTTP(S), even if the action="#" or action="", will cause a navigate, which should cause a new page load when the new GET parameters are added. If you want to prevent the page from reloading, you'll have to add a submit handler that prevents the default action by returning false or saying e.preventDefault().

心凉 2024-10-13 09:28:11

如果省略操作和方法会发生什么?如果您使用 ajax 调用提交,则无论如何您都不需要这些。

What happens if leave action and method out? You shouldn't need those anyways if you're submitting with an ajax call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文