@Wangww0925
2019-08-07T07:58:34.000000Z
字数 755
阅读 283
jQuery
url 请求路径type 请求方式 get | postasync 是否同步 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日
