AngularJS is caching JSONP by default

旧时模样 提交于 2020-01-05 08:43:49

问题


i'm new to AngularJS, and i'm writing an app that recives JSON data with callback via $http jsonp method. Caching parameter is not set, but browser caches data. How can i solve that?

$scope.fetch=function () {
$http({method: 'JSONP', url: 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero'})
.success(function(data) {
$scope.current =  data.salutation.toLowerCase();
console.log($scope.current);
$scope.dim=$scope.current; doIt();}).error(function(data) { 
$scope.current =   data.salutation.toLowerCase() || "Request failed";   $scope.dim=$scope.current;});

};


回答1:


Not sure exactly what angular's doing, but this is typically done by appending a timestamp to the url. Change your original URL from:

'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero'

To:

'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero&_=' + (new Date().getTime())


来源:https://stackoverflow.com/questions/15956768/angularjs-is-caching-jsonp-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!