Refresh Part of Page (Div)

Refresh Part of Page (div)

Use Ajax for this.

Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server. The data will then (again via jQuery) be put inside the same div in question and replace old content with new one.

Relevant function:

http://api.jquery.com/load/

e.g.

$('#thisdiv').load(document.URL +  ' #thisdiv');

Note, load automatically replaces content. Be sure to include a space before the id selector.

How do I refresh a DIV content?

To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in this case #here:

function updateDiv()
{
$( "#here" ).load(window.location.href + " #here" );
}
  • Don't disregard the space within the load element selector: + " #here"

This function can be called within an interval, or attached to a click event

Reload Specific part of the Page with JQUERY

Use jquery Ajax which will help you reload only the div

http://api.jquery.com/jquery.ajax/

or you can do this by

$("#main").load(location.href + " #main");

How to refresh just a specific portion of an HTML page?

You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax.

Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier.

iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame.

Not sure if this is what you're looking for, but hope it helps somewhat.



Related Topics



Leave a reply



Submit