I have found a fairly generic script for refreshing the content of a div without refreshing the whole page and although it works fine, there are a few things I would like to improve on if they are possible.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("#refreshdiv").load("activity.php");
var refreshId = setInterval(function() {
$("#refreshdiv").load('activity.php?randval='+ Math.random());
}, 9000);
$.ajaxSetup({ cache: false });
});
</script>
<div id="refreshdiv">
</div>
There are, in all, 6 divs that I am looking to refresh. 3 of them show on every page and the other 3 are all on the same page (giving a total of 6 on that page) and my 2 questions are.......
1. All of the divs are pulling results from a MySQL db, via Php, and what I have had to do for now is set up a new page for each of the divs content and have them pulled into the requesting page, resulting in 6 new pages.
The main problem with this is that each refresh on each div is counting as a page impression on the hosting company's analytics, meaning we are not getting a true set of page view results.
Is there a way that I can keep the content all on the one page and have Ajax refresh the query/result within the div tags instead of loading/reloading an external page.
I assume that the '.load' section may be the key to this. My guess is that it would be possible to write a function that would do this but am not sure where to start.
2. At the moment, there are 6 different scripts to allow the refresh of 6 different divs. Is there a way to cover all 6 divs in one script? I would assume that I could name all the divs the same but if question 1 is not achievable, then I will still have to call 6 different pages within the script. I would imagine that I could wrap the whole page in a refreshing div but would guess that is not recommended.
Thanks in advance for any help.
Steve