【发布时间】:2014-02-01 17:45:10
【问题描述】:
如何缓存 $http 调用返回的 json 数据。我使用以下风格的 $http 调用:
$http({
url: 'SomeWebMethodUrl',
method: "POST",
data: "{'query':'somevalue'}",
headers: { 'Content-Type': 'application/json' }
}).success(function (data, status, headers, config) {
//something in success
}).error(function (data, status, headers, config) {
//something in error
});
我查看了以下教程:https://coderwall.com/p/40axlq 缓存来自 $http 调用的服务器响应。但它是在解释 $http.get() 样式,并且会缓存数据,如果绝对 URL 相同,则不会发出第二个 $http 请求。
当我的“数据”属性与将来相同的 webmethod 调用相同时,我可以在我的 $http 调用样式中使用缓存吗?我正在为我的 WebMethods 使用 ASP.net ASMX 网络服务。
【问题讨论】:
-
感谢@allenhwkim 我尝试使用 cache:true 参数,但 $http 调用仍然在每次调用时发生(而且我没有刷新浏览器并在单击某些按钮时一次又一次地调用它) .
标签: javascript asp.net json angularjs caching