1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| /* * 接口获取数据通过POST * 通过post方法获取数据 */ function getDataByPostSync(params, url) { var result = { code: -1, msg: '网络请求失败!' }; var Url_ = url + "?token=" + getTokenStr(); mui.ajax(Url_, { data: params, dataType: 'json', //服务器返回json格式数据 type: 'POST', //HTTP请求类型 async: true, timeout: 5000, //超时时间设置为5秒; headers: { 'Content-Type': 'application/json;charset=UTF-8' }, contentType: "application/json", success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功; if(data.code == '918'){ //账号被登陆,故推出登陆 app.setState({}); localStorage.setItem('ISONLINE','0'); localStorage.setItem('TOKENINFO',''); localStorage.setItem('TOKEN',''); localStorage.setItem('USERID',''); localStorage.setItem('USERDATA',''); mui.toast('您的账号被别人登陆了,请您重新登陆!建议及时修改登陆密码!'); mui.openWindow({ url: '../login.html', id: 'login', show: { aniShow: 'pop-in' }, waiting: { autoShow: false } }); } result = data; }, error: function(xhr, type, errorThrown) { //异常处理; var err_ = { code: "-1", msg: "网络请求错误!" }; mui.toast(' 错误状态 xhr.status:' + xhr.status + ' 响应状态 xhr.readyState: ' + xhr.readyState + ' 捕获的异常: ' + errorThrown); result = err_; } }); return result; }
/* * 接口获取数据通过POST * 通过post方法获取数据 */ function getDataByPost(params, url) { var result = { code: -1, msg: '网络请求失败!' }; var baseurl = localStorage.getItem('Url') var Url_ = ""; //没有使用token的请求需要再次过滤 if (url == baseurl + 'common/staff/send_forgetpwd_code' || url == baseurl + 'common/staff/update_pwd' || url == baseurl + 'common/companylist' || url == baseurl + 'common/staffregister') { Url_ = url; } else { Url_ = url + "?token=" + getTokenStr(); } mui.ajax(Url_, { data: params, dataType: 'json', //服务器返回json格式数据 type: 'POST', //HTTP请求类型 async: false, timeout: 5000, //超时时间设置为5秒; headers: { 'Content-Type': 'application/json;charset=UTF-8' }, contentType: "application/json", success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功; result = data; }, error: function(xhr, type, errorThrown) { //异常处理; var err_ = { code: "-1", msg: "网络请求错误!" }; mui.toast(' 错误状态 xhr.status:' + xhr.status + ' 响应状态 xhr.readyState: ' + xhr.readyState + ' 捕获的异常: ' + errorThrown); result = err_; } }); return result; }
|