zoukankan      html  css  js  c++  java
  • Ajax

    aInpt.onclick=function(){
      // 1. 第一步
      if(window.XMLHttpRequest)
      {
        var oAjax=new XMLHttpRequest(); //兼容标准IE 谷歌 火狐
      }
      else{
        var oAjax=new ActiveXObject("Microsoft.XMLHTTP");
      }
      // 2. 链接服务器 open(方法, 文件名, 异步传输)
      oAjax.open('GET','data.txt?t='+new Date().getTime(),true);
      // 3. 发送请求
      oAjax.send();
      //4 接收返回
      oAjax.onreadystatechange=function(){
        if(oAjax.readyState==4) //读取完成
        {
          if(oAjax.status==200)
          {
            alert('数据接收');
          }
          else{
            alert('返回失败');
          }
        }
      }
    }

    //函数封装

    function ajax(url, fnSucc, fnFaild)
    {
      //1.创建Ajax对象
      if(window.XMLHttpRequest)
      {
        var oAjax=new XMLHttpRequest();
      }
      else
      {
        var oAjax=new ActiveXObject("Microsoft.XMLHTTP");
      }

      //2.连接服务器(打开和服务器的连接)
      oAjax.open('GET', url, true);


      //3.发送
      oAjax.send();

      //4.接收
      oAjax.onreadystatechange=function ()
      {
        if(oAjax.readyState==4)
        {
          if(oAjax.status==200)
          {
            //alert('成功了:'+oAjax.responseText);
            fnSucc(oAjax.responseText);
          }
          else
          {
            //alert('失败了');
            if(fnFaild)
            {
              fnFaild();
            }
          }
        }
      };
    }

  • 相关阅读:
    G a+b+c+d=?
    H Kuangyeye and hamburgers
    python 实现加法
    高精度板子
    angular项目一
    angular大牛的博客
    autocomplete
    angular的 表单
    快捷方式控制台调试each这种方法的时候怎么停
    自己练习的一些应该熟记的代码
  • 原文地址:https://www.cnblogs.com/zhengyan/p/5007455.html
Copyright © 2011-2022 走看看