@Wangww0925
2019-08-07T07:58:34.000000Z
字数 755
阅读 211
jQuery
url 请求路径
type 请求方式 get | post
async 是否同步 true 默认,异步 | false 同步
contentType "application/json;charset=utf-8"
data 请求参数
success 请求成功的回调
error 请求失败的回调
$.ajax({
url: "路径",
type: "post",
contentType: "application/json;charset=utf-8",
data: "",
success: function(data){
console.log(data)
},
error: function(res){
console.log(res)
}
})
/**
* jQuery ajax封装
* 调用
getAjaxOptions({
async: false, // 同步
data: "",
success: function (result){
console.log(result)
}
})
*/
function getAjaxOptions(options){
var opts = {
contentType: "application/json;charset=utf-8",
type: "POST",
async: true // true 异步(默认) / false
}
$.extend(opts, options);
opts.success = function(data) {
opts.success ? opts.success(data) : ""
};
opts.error = function(res) {
opts.err ? opts.err(res) : ""
};
$.ajax(opts);
}
作者 wendy
2019 年 6月 5日