jQuery 重新加载论坛后表单提交失败
我已经多次遇到这个问题,并且总是找到解决方法,但这一次可能是不可能的。
问题是这样的。我在 DIV 中有一个表单,我使用 jQuery AJAX 提交表单,然后使用添加的新数据重新加载表单(例如项目列表,以及将新项目添加到列表中的表单)。这些项目也被添加到 MySQL 数据库中。这工作正常,但是一旦页面重新加载,表单就不再将数据传递给脚本。
我认为这也与重新加载表单有关,并且没有链接到 javascript 函数(或类似的函数)。我之前已经通过将表单移动到重新加载 DIV 之外来解决这个问题,这确实有效,但这次它不切实际,而且我的表单是删除 DIV 内的列表项的按钮。
我本来打算尝试使用链接来提交隐藏表单,但我想在使用之前我不妨将此作为学习的机会。
所以我的问题是,我做错了什么以及如何解决?谢谢:)
闪闪发光*
I've hit this problem a few times, and I've always just found a work around, but this time that would probably be impossible.
The problem is this. I have a form inside a DIV, and I submit the form using jQuery AJAX and then reload the form with the new data added (eg a list of items, with a form to add new items to the list). The items are also added to a MySQL database. This works fine, however once the page is reloaded the form no longer passes the data to the script.
I assume it is something to do with the form being reloaded too and not being linked to the javascript function (or something like that). I've solved it previously by moving the form to outside the reload DIV, which does work, but this time it was impractical, and my forms are buttons which delete list items within the DIV.
I was about to try using links to submit a hidden form, but I thought before I resort to that I may as well use this as a chance to learn.
So my question is, what have I been doing wrong and how can I solve it? Thanks :)
Sparkles*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在处理
submit
的位置如下:使用
.live()
相反,如下所示:
当您执行
$("selector").submit(...)
时,它将一个处理程序绑定到然后找到的元素(不是后来添加的元素,即使它们与选择器匹配)。.live()
的工作方式不同,监听事件冒泡document
...所以它也适用于未来的元素。Where you handle the
submit
now like this:Use
.live()
instead, like this:When you do
$("selector").submit(...)
it binds a handler to thesubmit
event of the elements it found then (not the ones added later, even if they match the selector)..live()
works differently, listening for the event to bubble up dodocument
...and so it works on future elements as well.