/**
* @description 请求通用方法
* @param 请求配置选项 options {{url:string, type:string, data:any, contentType: string, callback:Function}}
*/
function localAjax(options){
var request_headers = {}
try{
if (token) {
request_headers.token = token
}
}catch(e){
//TODO handle the exception
}
$.ajax({
type: options.type !==undefined ? options.type:"get",
url: base_url + options.url,
headers: request_headers,
dataType: "json", // 请求返回时的数据格式
traditional:options.traditional !==undefined ? options.traditional : false, //traditional为false,会深度序列化参数对象; 为true阻止深度序列化,提交数组参数设置为true
async:options.async !==undefined ? options.async : true, // 文件上传时,contentType = false,
processData:options.processData !==undefined?options.processData:true, // 文件上传时,processData = false
contentType:options.contentType !==undefined ? options.contentType : "application/json", // 请求提交的数据格式 "application/x-www-form-urlencoded; charset=utf-8"
data:options.data !==undefined ? options.data : null, // 文件上传时 data 使用formdata
success: function (result) {
//TODO
if(options.callback){
options.callback(result)
}
console.log(result)
},
error: function (data, type, err) {
alert("请求失败,稍后再试,或者联系管理员!");
console.log(type);
console.log(err);
},
complete:options.complete
});
}