First, let's list the implementation of Ajax in jquery and prototype.
Jquery:
CopyCode The 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?
prototype has a caching mechanism for the same URL. Therefore, the page cannot be refreshed, especially when you use F5 or click "refresh, there will be a bug in the Ajax response area, so the prototype must not be refreshed.
Add a random number to the URL in prototype.
Original: var remoteurl = 'index. php';
after modification: var remoteurl = 'index. php? Rand = '+ math. Random ();
use the get method to generate a parameter irrelevant to the page display.