AngularJS HTTP GET请求返回缓存数据
发布时间:2020-12-17 17:16:35 所属栏目:安全 来源:网络整理
导读:在我的AngularJS应用程序中,我发送HTTP GET请求,如下所示. MyService.HttpReq("testUrl","GET",null); HttpReq方法在服务中定义,实现如下: this.HttpReq = function(URL,method,payload){ $http({ url: URL,method: method,cache: false,data: postData,hea
在我的AngularJS应用程序中,我发送HTTP GET请求,如下所示.
MyService.HttpReq("testUrl","GET",null); HttpReq方法在服务中定义,实现如下: this.HttpReq = function(URL,method,payload) { $http({ url: URL,method: method,cache: false,data: postData,headers: { 'Content-Type': 'application/json',} }).success(function(response) { console.log("Success: "+JSON.stringify(response)); }).error(function(data,status) { console.error("Error"); }); } 首先,这是在AngularJS中发送HTTP请求的正确方法吗? UPDATE 根据评论和回答,我已经更新了我的HTTP请求代码,如下所示,但仍然遇到同样的问题. this.HttpReq = function(URL,data: payload,'Cache-Control' : 'no-cache' } }). then( function(response) { var data = response.data; console.log("Success: "+JSON.stringify(data)); },function(response) { var data = response.data || "Request failed"; var status = response.status; console.error("Error: "+JSON.stringify(data)); } ); } 解决方法
只需将cache:false属性添加到配置对象即可.
https://docs.angularjs.org/api/ng/service/$http#caching 您还可以添加标题:’Cache-Control’:’no-cache’ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读