zoukankan      html  css  js  c++  java
  • ajax

    $.ajax({
            type: 'GET',//请求类型
            url: 'https://open.duyiedu.com/api/student/findAll',//请求地址
            beforeSend: function (xhr, request) {//发出请求之前执行的函数,请求拦截
                console.log(request.data);
            },
            data: {
                page: 1
                // appkey:'pppp_1569994479435'//请求参数
            },
            contentType: '',//编码类型
            dataFilter: function (data, type) {//,响应拦截,返回拦截
    
            },
            dataType: 'json',//得到的数据类型
            success: function (res) {//成功的回调函数
                console.log(res);
            },
            error: function () {
            }
        });
    /**
     * 
     * @param {*} methods 
     * @param {*} url 
     * @param {*} data 
     * @param {*} callBack 
     */
    function ajax(method, url, data, callBack) {
        var xhr = null;
        if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        } else {
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
        }
        if (method == 'GET') {
            xhr.open(method, url + '?' + data, true);
            xhr.send();
        } else {
            xhr.open(method, url, true);
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(data);
        }
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    callBack(JSON.parse(xhr.responseText));
                }else{
                    console.log('error');
                }
            }
        }
    }
  • 相关阅读:
    20180818
    20200817
    [mac操作]程序运行技巧与注意事项
    [py编程]小白新奇的技巧
    [命令]使用的conda命令大全
    【编程】python文件读写
    latex学习
    [记录]菜鸡划水记录
    【pytorch】pytorch入门学习
    pycharm中出现unresolved reference的解决办法
  • 原文地址:https://www.cnblogs.com/pengppp/p/11778046.html
Copyright © 2011-2022 走看看