Ajax reconstruction XMLHttpRequest

Source: Internet
Author: User
// Refactor XMLHttpRequest
VaR net = new object (); // The parameter net. ready_state_uninitialized = 0; net. ready_state_loading = 1; net. ready_state_loaded = 2; net. ready_state_interactive = 3; net. ready_state_complete = 4; net. contentloader = function (URL, onload, onerror) {// structure function number this. url = URL; this. req = NULL; this. onload = onload; this. onerror = (onerror )? Onerror: This. defaulterror; this. loadxmldoc (URL);} net. contentloader. prototype = {loadxmldoc: function (URL) {// rename the initxmlhttprequest function if (window. XMLHttpRequest) {// reconstructs the loadxml function this. req = new XMLHttpRequest ();} else if (window. activexobject) {This. req = new activexobject ("Microsoft. XMLHTTP ");} If (this. REQ) {try {var loader = this; this. req. onreadystatechange = function () {loader. onre Adystate. call (loader);} This. req. open ('get', URL, true); // reconstructs the sendrequest function this. req. send (null);} catch (ERR) {This. onerror. call (this) ;}}, onreadystate: function () {// re-structured response function var Req = This. REQ; var ready = req. readystate; If (ready = net. ready_state_complete) {var httpstatus = req. status; If (httpstatus = 200 | httpstatus = 0) {This. onload. call (this);} else {This. onerror. call (Th Is) ;}}, defaulterror: function () {alert ("error fetching data! "+" \ N \ nreadystate: "+ this. req. readystate + "\ nstatus:" + this. req. status + "\ nheaders:" + this. req. getAllResponseHeaders () ;}} function mycallback () {alert {This. URL + "loaded! Here's the content: \ n "+ this. Req. responsetext };}

 

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.