jquery----AJAX请求

常用到的参数

// 常用参数
    var obj = {
        type: 'GET', //请求的类型,GET、POST等	
        url: 'www.baidu.com', //向服务器请求的地址。
        contentType: 'application/json', //向服务器发送内容的类型,默认值是:application/x-www-form-urlencoded
        dataType: 'JSON', //预期服务器响应类型   JSON   JSONP
        async: true, //默认值是true,表示请求是异步的,false是同步请求,同步请求会阻碍浏览器的其他操作(不建议使用)
        timeout: '5000', //设置本地的请求超时时间(单位是毫秒)
        cache: true, //设置浏览器是否缓存请求的页面
        success: function (result, status, XMLHttpRequest) { //请求成功是执行的函数,result:服务器返回的数据,    status:服务器返回的状态,
        },
        error: function (xhr, status, error) { //请求失败是执行的函数
        },
        complete: function (xhr, status) { //不管请求失败还是请求成功,都执行的函数
        }
    }

案列

$(function () {
        $.ajax({
            type: 'POST',
            url: 'https://minih.com/find',
            dataType: 'json',
            data: {
                token: 'mu_2389f129-463d-4955-88c2-4a701c69a310',
                key: '',
                st: 1 //页码
            },
            success: function (data) {
                var arrLen = data.list.length;
            },
            error: function (xhr, type) {
                console.log('网络错误')

            }
        });

    })

猜你喜欢

转载自blog.csdn.net/Candy_mi/article/details/87878730
今日推荐