Differences between prototype and Ajax implementation in jquery

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.