zoukankan      html  css  js  c++  java
  • 简单的 创建AJax的方法

    // 简单的ajax对象
              var myAjax = {
                // XMLHttpRequest IE7+, Firefox, Chrome, Opera, Safari ;  ActiveXObject IE6, IE5
                xhr: window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'),
                get: function(url, callback){
                  this.xhr.open('get', url);
                  this.onreadystatechange(callback, this.xhr);
                  this.xhr.send(null);
                },
                post: function(url, data, callback){
                  this.xhr.open('post', url);
                  this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                  this.onreadystatechange(callback, this.xhr);
                  this.xhr.send(data);
                },
                onreadystatechange: function(func, _xhr){
                  _xhr.onreadystatechange = function(){
                    if(_xhr.readyState == 4){
                      if (_xhr.status == 200){
                        func(_xhr.responseText);
                      }
                    }
                  }
                }
              };
    

      

  • 相关阅读:
    vue 定义全局函数和变量
    大学感受
    NOIP2018 游记
    NOI2018 游记
    THUSC 2018 游记
    APIO2018 游记
    SXOI2018游记
    poorpool 的 考场 NOI Linux 配置
    关于 poorpool
    NOIP2017 游记
  • 原文地址:https://www.cnblogs.com/laneyfu/p/7590976.html
Copyright © 2011-2022 走看看