38 lines
970 B
JavaScript
38 lines
970 B
JavaScript
// ajax 请求封装
|
|
function ajaxRequest(url, type, data, async, beforeFn, successFn, errorFn, contentType) {
|
|
$.ajax({
|
|
url: url,
|
|
type: type,
|
|
headers: {
|
|
"authorization": token
|
|
},
|
|
data: data,
|
|
async: async,
|
|
beforeSend: beforeFn,
|
|
contentType: contentType || "application/x-www-form-urlencoded; charset=utf-8",
|
|
success: function (event, xhr, settings, data){
|
|
event=modifyResponseData(event);
|
|
successFn(event, xhr, settings, data);
|
|
},
|
|
error: errorFn
|
|
});
|
|
}
|
|
|
|
// 文件上传
|
|
function ajaxRequest2(url, type, data, beforeFn, successFn, errorFn) {
|
|
$.ajax({
|
|
url: url,
|
|
type: type,
|
|
data: data,
|
|
headers: {
|
|
"authorization": token
|
|
},
|
|
async: true,
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
beforeSend: beforeFn,
|
|
success: successFn,
|
|
error: errorFn
|
|
});
|
|
} |