"heartbeat" Logger Qustion
Solution 1:
IE does cache Ajax requests. In order to stop that I normally just add a random variable to my request:
functionlogTime() {
var xhReq = newXMLHttpRequest();
xhReq.open("GET", "ajax-on-time-interval.cfm?random="+Math.random(), false);
xhReq.send(null);
var serverResponse = xhReq.responseText;
alert(serverResponse);
}
That should work as long as you aren't parsing the new 'random' variable on the back-end :-)
Solution 2:
You can get away with making a HEAD request instead of a full get if you are just pinging the server and do not care what comes back.
Also using a synchronous request is a VERY BAD idea. That means if the connection to the server is bad for any reason, the user's browser will freeze and they will not be able to do anything. Test it out by adding a long sleep time on your serverside code and play with the page. Your user's will not enjoy that type of ping so swap it for asynchronous.
To stop the caching, you should set the right headers on your serverside code to begin with. If you do not set the correct, the browser will cache the page. That is what get requests are meant to do to make your browsing more efficient.
If you want to force it to always grab the newest, easiest thing to do is append a querystring value that changes. Math.random() is a common choice, but a better choice is new Date().getTime()
since it is always a different value on the same machine.
"ajax-on-time-interval.cfm?ts=" + (newDate().getTime())
Solution 3:
I think you can use
$.ajaxSetup({
cache: false
});
or its something like that...
Post a Comment for ""heartbeat" Logger Qustion"