zoukankan      html  css  js  c++  java
  • ajax的get,post ,封装

    let ajax = new Object();

    ajax.get = function(url,fn){

      //创建ajax对象

      let xhr = new XMLHttpRequest();

      //与服务器建立连接

      xhr.open('GET',url,true);

      //发送请求

      xhr.send();

      //等待返回的数据

      onreadystatechange = function(){

        if(xhr.readyState === 4 && xhr.status === 200){

          if(typeof fn=== 'function'){

          fn(xhr.responseText);

          }

        }

      }

    }

    ajax.post = function(url,data,fn){

      var xhr = new XMLHttpRequest();

      xhr.open('OPST',url,true);

      xhr.send(data);

      onreadtstatechange = function(){

      if(xhr.readystate === 200 && xhr.status === 4){

        if(typeof fn === 'function'){

          fn(xhr.responseText);

          }

        }

      }

    }

      

  • 相关阅读:
    送股分红是怎么回事?
    基金申购费用计算
    msn 爬楼梯
    沪市证券交易费用
    OS X
    见到郎咸平:)
    Long long time_Blog更新了
    生~气:)
    突然想起去年的今天
    久久沉思以后
  • 原文地址:https://www.cnblogs.com/tong-yao/p/10241297.html
Copyright © 2011-2022 走看看