Let's first enumerate AJAX implementations in jquery and prototype.
Jquery:
Copy Code code as follows:
<script language= "JavaScript" >
$ (function () {
var box = {};
var remoteurl = ' index.php ';
Box.interval = 5*60*1000;//5 minutes
Box.showboxinfo = function () {
Jquery.get (Remoteurl, function (data) {
var Msg_box = $ (' #msg_box ');
msg_box.innerhtml = data;
}
});
}
Box.run = function () {
This.showboxinfo ();
SetInterval (This.showboxinfo,this.interval);
};
Box.run ();
})
</script>
Prototype
Copy Code code as follows:
<script language= "JavaScript" >
var box = {};
Box.interval = 5*60*1000;//5 minutes
Box.showboxinfo = function () {
var pars = "";
var remoteurl = ' index.php ';
var myajax = new Ajax.request (
Remoteurl,
{
Method: ' Get ',
Parameters:pars,
OnComplete:box.showResponse
});
};
Box.showresponse = function (data) {
var Msg_box = $ ("Msg_box");
msg_box.innerhtml = Data.responsetext;
};
Box.run = function () {
This.showboxinfo ();
SetInterval (This.showboxinfo,this.interval);
};
Box.run ();
</script>
The actual introduction of the SetInterval function after the prototype is not refreshed, this is why?
The original is prototype for the same URL has caching mechanism, should not refresh the page, especially when users use F5 or click "Refresh", will appear in the Ajax response area blank bug, so you must let prototype not refresh.
To add a random number to a URL in prototype
Original: var remoteurl = ' index.php ';
Modified: var remoteurl = ' index.php?rand= ' +math.random ();
Use a Get method to produce a parameter that is independent of the page display.