jQuery.get不接收对服务器的最新版本的文件的 [英] jQuery.get doesn't receive latest version of file on server

查看:210
本文介绍了jQuery.get不接收对服务器的最新版本的文件的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
   prevent AJAX调用缓存

我使用jQuery来读取Web服务器上的一个小文本文件:

I'm using jQuery to read a tiny text file on a web server:

jQuery.get('scores.txt', function(data) {
    parseScores(data);
});

这几乎工程,因为它应该 - 但它并不可靠加载最新版本的文件。即使 story.txt 已经改变,刷新页面数据返回完全相同的值

This nearly works as it should -- but it doesn't reliably load the latest version of the file. Even if story.txt has changed, refreshing the page returns exactly the same value for data.

该服务器是标准的Mac OS的Apache,不启用缓存,它是在同一台机器作为客户端 - 所以理论上没有其他高速缓存它和我坐在

The server is standard Mac OS Apache, with no caching enabled, and it's the same machine as the client -- so in theory there are no other caches sitting between me and it.

如果我加载 http://127.0.0.1/scores.txt 到浏览器则始终打开最新版本。

If I load http://127.0.0.1/scores.txt into the browser then it always opens the latest version.

在Apache日志看,该页面无法更新,与时俱进,jQuery的GET请求不会到达服务器。

Looking at the Apache log, for the times the page fails to update, the jQuery GET request never reaches the server.

我怀疑,我可能需要移动这个问题serverfault.com,但任何人都可以看到我的JavaScript的问题,将使其在这样的行为?

I have a suspicion that I might need to move this question to serverfault.com, but can anyone see a problem with my JavaScript that would make it behave in this way?

有没有使用JavaScript / jQuery来强制浏览器请求文件的新副本的方法吗?

Is there any way of using JavaScript/jQuery to force the browser to request a new copy of the file?

先谢谢了。

推荐答案

尝试添加 缓存:假 您的AJAX选项:

Try adding cache: false to your AJAX options:

jQuery.ajax({
    url: 'scores.txt',
    dataType: 'text',
    type: 'GET',
    cache: false,
    success: parseScores
});

jQuery将自动添加一个的cache preventing时间戳每个请求。

jQuery will automatically add a cache-preventing timestamp to each request.

这篇关于jQuery.get不接收对服务器的最新版本的文件的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆