http.jsonp 返回缓存数据,直到手动刷新页面

http.jsonp coming back with cached data until manual page refresh

我的数据应该是当前时间,但我发现当我通过 $http.jsonp 加载新数据时,我的数据每次都作为缓存数据进入。我怎样才能改变它,以便我每次都能得到 unchached 数据?

这是我的逻辑测试:

$http.jsonp("mydataurl?_jsonp=JSON_CALLBACK").success(function(data){
  console.log(data); // always logs 0.76608400 1431562002 (only updates when I manually refresh the page)
});

php

<?php

echo $_GET['_jsonp'] . "(" . microtime() . ")";

?>

您可以在 url 的末尾附加一个随机字符串以避免缓存。

$http.jsonp("mydataurl?_jsonp=JSON_CALLBACK&random=123").success(function(data){
  console.log(data); // always logs 0.76608400 1431562002 (only updates when I manually refresh the page)
});

只需确保随机数每次都有不同的值。您可以在查询中使用日期 "mydataurl?_jsonp=JSON_CALLBACK&random="+new Date()