A simple analysis of AJAX data requests _jquery

Source: Internet
Author: User
Like what:
Copy Code code as follows:

function Xmlhttpr () {
var xmlhttp;
if (window. XMLHttpRequest) {
Xmlhttp=new XMLHttpRequest ();
}
else{
Try{xmlhttp=new ActiveXObject ("Msxml2.xmlhttp")}
catch (e) {
Try{xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {return null;
}
}
return XMLHTTP;

In this way, you can basically create a Cross-browser object;
The following is the simple use of Ajax, using the XMLHttpRequest object to complete;
Copy Code code as follows:

var ajaxel=new Object ();
Ajaxel is a custom namespace;
Ajaxel.contentload=function (URL) {
IE browser, will enable caching, where the URL added to the Date field is to prevent IE use caching, of course, can also use Math.random () produce and gettime similar effect;
url+= "? date=" +new date (). GetTime ();
This.req=null;
This.url=url;
This callback function is the update function on the page of the data;
This.onload=function () {
Domel is a DOM element with an ID of #test;
var Domel=document.getelementbyid ("Test");
In addition to using the ResponseText property, you can also use Responsexml to obtain a data table;
Domel.innerhtml=this.req.responsetext;
}
This. Xmlhttp (URL);
}
ajaxel.contentload.prototype={
Xmlhttp:function (URL) {
if (window. XMLHttpRequest) {
This.req=new XMLHttpRequest ();
}
else{
Try{this.req=new ActiveXObject ("Msxml2.xmlhttp")}
catch (e) {
Try{this.req=new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e) {return null;
}
}
}
if (this.req) {
var xmlr=this;
This.req.onreadystatechange=function () {
if (xmlr.req.readystate===4) {
XmlR.onload.call (XMLR);
}
}
This.req.open ("Get", url,true);
This.req.send (NULL);
}
}
}
var xmle=new ajaxel.contentload ("main.php");

Main.php inside, I set the simpler sample code here: A similar display appears on the page: now! Time Is:05:18:10 AM 2011, which can be changed dynamically.
Copy Code code as follows:

echo "now! Time is: ". Date (" H:i:s a Y ");
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.