jQuery json缓存,是否有办法改变时间戳url键

jQuery jsonp caching, is there a way to change timestamp url key?

本文关键字:改变 时间戳 url json 缓存 是否 jQuery      更新时间:2023-09-26

你好,我正在创建一个jsonp api,我在我的$.ajax()设置中使用cache = false。然而,我的服务器需要一个特定的前缀在每个url前GET参数。

交货。http://www.domain.com/test?_prefix_age=29

我已经完成了这样的事情,但我找不到一种方法来添加我的前缀在缓存时间戳参数_:{TIMESTAMP}

From jQuery $.ajax() docs:

cache(默认值:true,对于数据类型'script'和'jsonp'为false)布尔值如果设置为false,将强制不访问请求的页面由浏览器缓存。注意:将cache设置为false只会起作用正确使用HEAD和GET请求。它通过追加来工作"_={timestamp}"作为GET参数。不需要此参数其他类型的请求,除了在IE8中对URL进行POST时

是否有任何方法可以在时间戳参数前面添加前缀而不会搞乱jQuery内部?

你可以不使用jQuery。例子:

<script>
function processJSON (json) {
  // Do something with the JSON response
};
// Create a new script element
var script_element = document.createElement('script');
// Set its source to the JSONP API
script_element.src = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=processJSON&tags=monkey&tagmode=any&format=json';
// Stick the script element in the page <head>
document.getElementsByTagName('head')[0].appendChild(script_element);
</script>
创建自己的JSONP函数的障碍可能足够低,可以跳过尝试使jquery工作?

摘自http://schock.net/articles/2013/02/05/how-jsonp-really-works-examples/