代码如下
var AppAjax ={ baseUrl:AppConfig.apiUrl //【POST请求】,post:function(pUrl,pData,pSuccessFun){ pUrl = AppAjax.baseUrl + pUrl; $.ajax({ headers: { token: AppConfig.token },url:pUrl,type:‘POST‘,data:JSON.stringify(pData),//pData,//JSON.stringify(), contentType:"application/json",beforeSend:function (request) { },success:function(respondData){ if(AppAjax.responseFormat(pUrl,respondData)){ pSuccessFun(respondData); } },error:function(respondData){ AppAjax.responseFormat(pUrl,respondData) } }); } //【GET请求】,get:function(pUrl,pSuccessFun){ pUrl = AppAjax.baseUrl + pUrl; $.ajax({ headers: { token: AppConfig.token },type:‘GET‘,contentType:"application/json",respondData) } }); } //【请求统一处理】,responseFormat:function(url,respondData){ //console.log(respondData) if(respondData.status == 404){ alert("接口404") }else if( respondData.success === false){ alert(respondData.msg) if(respondData.code == 401){ window.location.href = AppConfig.loginPage; alert("重新登录") }else{ $("body").html("<div align=‘center‘><h1>"+respondData.msg+"</h1></div>") } }else{ } return true; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。