jQuery对Ajax的封装

473 阅读1分钟
$.ajax({    dataType: 'json', // 设置返回值类型    contentType: 'application/json', // 设置参数类型    headers: {'Content-Type','application/json'},// 设置请求头    xhrFields: { withCredentials: true }, // 跨域携带cookie    data: JSON.stringify({a: [{b:1, a:1}]}), // 传递参数    error:function(xhr,status){  // 错误处理       console.log(xhr,status);    },    success: function (data,status) {  // 获取结果       console.log(data,status);    }})