zoukankan      html  css  js  c++  java
  • 封装AJAX

    function Ajax(obj) {
        let xmlhttp = '';
        if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else { // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open(obj.type, obj.url, true);
        xmlhttp.setRequestHeader('content-type', 'application/json');
        let param = '' || JSON.stringify(obj.param)
        xmlhttp.send(param);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                let data = JSON.parse(xmlhttp.responseText)
                obj.success(data)
            }
        }
    }
    let ajax = Ajax
    ajax({
        type: 'POST',
        url: 'http://xxx',
        param: {
            name: 'zhangsan',
            password: '1234'
        },
        success: function(res) {
            console.log(res)
        }
    })
    

      

  • 相关阅读:
    $prufer$序列
    倍增
    二分
    英语词汇速查表
    ACM模拟赛
    Trie树
    关于军训的模拟赛-R2
    树上差分
    列队
    斜率优化dp
  • 原文地址:https://www.cnblogs.com/zpfqi/p/14913872.html
Copyright © 2011-2022 走看看