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