zoukankan      html  css  js  c++  java
  • ajax异步操作学习

    创建xhr对象实现浏览器全兼容         

      function createXmlHttp() {//创建xhr对象          

           var xhobj = false;              

       try {               

          xhobj = new ActiveXObject("Msxml2.XMLHTTP"); // ie msxml3.0+      

               } catch (e) {               

          try {                 

            xhobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml2.6           

              }

    catch (e2)

    {           

                  xhobj = false;          

               }            

         }              

       if (!xhobj && typeof XMLHttpRequest != 'undefined')

    {

    // Firefox, Opera 8.0+, Safari            

             xhobj = new XMLHttpRequest();         

            }            

         return xhobj;     

            }

    通过GET方式进行Ajax操作; var xhr;       

      window.onload = function () {             xhr = createXmlHttp();         }         function doAjax() {             xhr.open("GET", "Ajax.aspx?isAjax=1", true);             xhr.onreadystatechange = watching;             xhr.send(null);         }         function watching() {             if (xhr.readyState==4) {                 if (xhr.status == 200) {                     var txt = xhr.responseText;                     document.getElementById("hh").innerHTML = txt;                 }             }             else {                 document.getElementById("hh").innerHTML="服务器出错了"+xhr.status;             }         }

  • 相关阅读:
    temp12
    temp111
    test.c
    vipLogin.c
    services.c
    request.c
    managerLogin.c
    将博客搬至CSDN
    SpringMabatis整合项目mybatis-configuration.xml核心配置
    logback-test.xml配置文件模板
  • 原文地址:https://www.cnblogs.com/msdncrazy/p/3021279.html
Copyright © 2011-2022 走看看