Prototype and jquery under the AJAX implementation of the difference _javascript skills

Source: Internet
Author: User
Tags setinterval
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.
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.