Ajax Asynchronous Call Framework

Source: Internet
Author: User
Tags window
ajax| Asynchronous /*
Author: welfred
Time: August 14, 05
Function: Ajax Asynchronous call framework
*/
var req;

Retrieve XML document (reusable generic function);
parameter is URL string (relative or complete) to
An. xml file whose content-type is a valid XML
Type, such as Text/xml; XML source must is from
Same domain as HTML file
function Ajax (URL) {

req = false;

Branch for native XMLHttpRequest object
if (window. XMLHttpRequest) {
try {
req = new XMLHttpRequest ();
catch (e) {
req = false;
}
Branch for ie/ Windows ActiveX version
else if (window. ActiveXObject) {
try {
req = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {
try {
req = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {
req = false;
}
}
}
if (req) {
Req.onreadystatechange = Processreqchange; Once the state changed,the function "Processreqchange" would be excuted.
Req.open ("Get", url, True);
Req.send ();
}
}

/*wait for the response*/
function Processreqchange ()
{
Only if req shows "complete"
if (req.readystate = = 4) {
only if "OK"
if (Req.status = = 200) {
This is your bussiness code
Procbusiness ();
} else {
Alert ("Get the data!) \ n Please ensure that your Network The connection is smooth, otherwise, please contact the administrator in time, thank!:\ N "+ req.statustext);
}
}
}

/*
Read the XML file and retrive the data * *
function procbusiness () {
var xmlresult = Req.responsexml;
var root = xmlresult.documentelement;

Todo


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.