function ajax_http_request(url, method, data, callback) {
var header = {'If-Match': '1.0.0'};
var token = cookie.get('token');
if (typeof(token) == 'string' && token != '') {
header.token = token;
}
if (method === 'get') {
var page = 1, page_size = 1;
if (data != null && !isNaN(parseInt(data.page))) {
page = Math.max(page, parseInt(data.page));
}
if (data != null && !isNaN(parseInt(data.page_size))) {
page_size = Math.max(page_size, parseInt(data.page_size));
}
header.range = page + '/' + page_size;
}
$.ajax({
type: method.toUpperCase(),
url: system.url + url,
data: data,
dataType: 'json',
timeout: 5000,
headers: header,
success: function(response){
if (response.error == 3 || response.error == 4) {
cookie.move('token');
location.href = '/file/iuser/login.html';
} else {
callback(response);
}
},
error: function(xhr, type){
popup.tip('服务异常,请稍后再试',3);
}
});
}