Native Ajax implementation code

Source: Internet
Author: User

//开始初始化XMLHttpRequest对象      if(window.XMLHttpRequest)       {   //Mozilla 浏览器          ajax = new XMLHttpRequest();          if (ajax.overrideMimeType)           {   //设置MiME类别              ajax.overrideMimeType("text/xml");          }      }      else if (window.ActiveXObject)       {   // IE浏览器          try           {              ajax = new ActiveXObject("Msxml2.XMLHTTP");          }           catch (e)           {              try               {                  ajax = new ActiveXObject("Microsoft.XMLHTTP");              }               catch (e) {}          }      }      if (!ajax)       {   // 异常,创建对象实例失败          window.alert("不能创建XMLHttpRequest对象实例.");          return false;      }                        //通过Post方式打开连接      ajax.open("GET", url, true);       //定义传输的文件HTTP头信息      //ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");          ajax.setRequestHeader("If-Modified-Since","0");      //发送POST数据      ajax.send(null);       //获取执行状态      ajax.onreadystatechange = function()       {           //如果执行状态成功,那么就把返回信息写到指定的层里          if (ajax.readyState == 4 && ajax.status == 200)           {               cdown.innerHTML = ajax.responseText;           }       }  

 

Native Ajax implementation code

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.