/**
- Get请求
- @param {String} 请求action名称
- @param {JSON} GET数据
- @param {Function} 执行成功回调函数
-
@param {Function} 执行完成回调函数
*/
http.get = function(action, data, success, compelete, token) {
var params = getParams(data);
var url = [];
url.push(action);
var obj = new XMLHttpRequest(); // XMLHttpRequest对象用于在后台与服务器交换数据obj.open('GET', url.join(""), true); obj.setRequestHeader("X-Requested-With", "bikuex"); obj.setRequestHeader("Accept", "application/json"); if(token) { obj.setRequestHeader("Authorization", "Basic " + token); } obj.onreadystatechange = function() { if(compelete) { compelete(obj.status, obj.readyState); } if(obj.readyState == 4 && obj.status == 200 || obj.status == 304) { var ret = JSON.parse(obj.responseText); if(ret.status == 1001 || ret.status == 1002) { Page.toast("你还未登录,请先完成登录!"); Page.ShowLogin(); } else if(ret.status == 1003) { console.log("过期登录===========111111111111=======") Page.toast("登录已过期,请重新登录"); Page.ShowLogin(); } else if(ret.status == 1004) { Page.toast("你的账号已在其他地方登录!"); Page.ShowLogin(); } if(success) success(ret); } else if(obj.status == 401) { localStorage.setItem("IsLogin", "0") //ToDo:Token认证失败,需要重新登录 } else if(obj.status == 500) { //ToDo:系统后台报错 } }; obj.send();
};
0 个回复