简体   繁体   中英

Reload part of a page AJAX

I have an AJAX function that reloads the current page. Now I don't want to reload the whole page, is it possible to get for example the innerHTML of div#footer in http.responseText? What I actually want to do is:

document.getElementById("footer").innerHTML = http.responseText.getElementById("footer");

But of course it's not possible like that, and I don't want to rewrite the whole page that for example it only prints out the footer if a GET variable exists.. Any ideas? Thanks!

XMLHttpRequest it and parse it as a string?

h=http.responseText;
s1=h.substring(h.indexOf('<div id="footer"'));
s1=s1.substring(s1.indexOf('>')+1);
s1=s1.substring(0,s1.indexOf('</div>'));
document.getElementById("footer").innerHTML=s1

there

but if you have any more divs in footer this will grab it until the next div's end - create a new div after footer's </div> eg: </div><div id="end"></div>

and instead of

s1=s1.substring(0,s1.indexOf('</div>'));

do:

s1=s1.substring(0,s1.indexOf('</div><div id="end">'));

您应该使用document.createDocumentFragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM