First, let's list the implementation of Ajax in Jquery and prototype.
Jquery:
Copy codeThe Code is as follows:
<Script language = "javascript">
$ (Function (){
Var box = {};
Var remoteUrl = 'index. php ';
Box. interval = 5x60*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 codeThe Code is as follows:
<Script language = "javascript">
Var box = {};
Box. interval = 5x60*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 prototype cannot be refreshed after the setInterval function is introduced. Why?
It turns out that prototype has a caching mechanism for the same URL. Therefore, the page cannot be refreshed, especially when users use F5 or click "refresh", there will be a bug in the Ajax response area, in this way, prototype must not be refreshed.
Add random numbers for URLs in prototype
Original: var remoteUrl = 'index. php ';
After modification: var remoteUrl = 'index. php? Rand = '+ Math. random ();
You can use GET to generate a parameter irrelevant to page display.