表单提交后 jQuery 部分页面刷新
当使用 jQuery 提交表单时,是否可以将生成的页面(提交后)放置在另一个 HTML 元素中?
我会尽力让这一点更清楚。到目前为止,我一直在使用回调方法,
document.forms['form'].submit();
只要表单已用新信息更新并且需要刷新,这些方法就会执行 a 。但是,这会导致整个页面刷新。我正在使用 jQuery 实现部分页面刷新,并考虑使用类似的方法
var newContent = jQuery('#form').submit();
jQuery('#div').load(newContent);
,但是,这似乎不起作用,因为页面仍然完全刷新。内容是正确的,但是行为似乎与以前完全相同 - 所以我不确定 jQuery 是否真的可以实现我想要的。任何提示和指示都会有帮助。
谢谢。
When using jQuery to submit a form is it possible to place the resulting page (after the submit) inside another HTML element?
I'll try to make this clearer. Up to now I've been using Callback methods that among others do a
document.forms['form'].submit();
whenever a form has been updated with new information and needs to be refreshed. However, this results in a full page refresh. I'm implementing Partial Page Refresh using jQuery and thought of using something like
var newContent = jQuery('#form').submit();
jQuery('#div').load(newContent);
However, that does not seem to work as the page is still fully refreshed. The content is correct, however the behaviour seems to be exactly the same as before - so I'm not really sure if what I want is actually possible with jQuery. Any hints and pointers would be helpful.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要做的是使用 ajax 方法之一来发布表单,并将输出注入到
success
回调中的元素中。例如:看看
$.post
和 < a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">$.ajax
What you would need to do is use one of the ajax methods to post your form, and inject the output into an element within the
success
callback. For example:Take a look at
$.post
and$.ajax
问题不清楚。花更多时间了解 jquery ajax api,以找到使用 jquery ajax 更新 dom 元素的更好方法。
如果您正在谈论由于 ajax 调用而导致 dom 更改后事件绑定不起作用。请参阅事件 api 中的 Jquery live/die 方法。
Question is not clear. Spend more time understanding the jquery ajax api to find better way of updating dom element using jquery ajax.
If you are talking about event bindings not working after dom change due to ajax call. Refer Jquery live/die methods in events api.