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
Why Is Using Onclick() in HTML a Bad Practice
How to Check Whether a Checkbox Is Checked in Jquery
JavaScript Code to Stop Form Submission
Retrieve the Position (X,Y) of an HTML Element
Why Isn't My JavaScript Working in Jsfiddle
Difference Between Properties and Attributes in Html
Get the Size of the Screen, Current Web Page and Browser Window
In JavaScript How to Make a "Click" Event Fire Programmatically For a File Input Element
Invoking JavaScript Code in an Iframe from the Parent Page
Capture HTML Canvas as Gif/Jpg/Png/Pdf
Communication Between Tabs or Windows
Why Calling Setstate Method Doesn't Mutate the State Immediately
Include Another HTML File in a HTML File
Jquery Mobile: Document Ready Vs. Page Events
Displaying Pdf from Arraybuffer