admin管理员组文章数量:1344184
Is this a valid way to refresh part of webpage:
$("#content").load(location.href+" #content>*","");
Note that I'm not requesting any new data here, but basically re-loading the content of a div as part of an .ajax success function.
This seems much easier than requesting data through an ajax function and loading that into the page, but I'm wondering if there are any drawbacks or issues with this method.
Is this a valid way to refresh part of webpage:
$("#content").load(location.href+" #content>*","");
Note that I'm not requesting any new data here, but basically re-loading the content of a div as part of an .ajax success function.
This seems much easier than requesting data through an ajax function and loading that into the page, but I'm wondering if there are any drawbacks or issues with this method.
Share Improve this question edited Nov 24, 2015 at 9:30 royhowie 11.2k14 gold badges53 silver badges67 bronze badges asked Jul 8, 2011 at 16:11 rolling stonerolling stone 13k9 gold badges48 silver badges63 bronze badges6 Answers
Reset to default 5This seems much easier than requesting data through an ajax function and loading that into the page,
The .load()
method sends an AJAX request, so no, it's not easier, it's absolutely the same :-) In addition to the standard $.get()
, $.post()
and $.ajax()
methods it allows you to provide a selector so that you can fetch only some portion of the returned HTML during the AJAX request. Maybe it is this that makes it more convenient in some situations. But behind the scenes all of those method end up calling $.ajax()
. They are just shorthands.
If you want to refresh part of a web page, say the content inside a element which has an ID or class of "content" : <div id="content" class="content">Content to refresh via ajax...</div>
$('#content').load('ajax/newcontent.html');
or
$('.content').load('ajax/newcontent.html');
The content returned from the url "ajax/newcontent.html" will replace the content inside the div element with an id or class = "content".
On this page: http://blog.mediasoft.be/partial-page-refresh-with-ajax-and-jquery/ it appears that some people are having trouble getting this to work on IE, so I'm going to assume it's not 100% reliable yet and will continue to use the standard way of refreshing content using JQuery for now.
Actually there are no issues, the load
action is a wrapper for jQuery.ajax
it makes also some validations and assigns the html to the selected element.
You could reload a section of the visible page using iframes, if you can accept their limitations.
Thanks @aruss. Just to be clear I'm not returning any HTML during the load action, but rather loading HTML from a div that's in the current webpage. – rolling stone 11 mins ago
--
Then there is no need to use the load() method. It's as simple as
$('#content').empty().html($('#idOfContentNeeded').html());
本文标签: javascriptRefresh part of a page using JQueryStack Overflow
版权声明:本文标题:javascript - Refresh part of a page using JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743747594a2532044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论