javascript - 定时 Javascript 文件刷新而不重新加载页面

标签 javascript jquery ajax

我有一个在我文档的 head 标签中调用的 javascript 文件,每隔 30 秒,我希望重新加载这个 javascript 文件。

我对此做了一些研究,似乎它在提取本地存储的文件副本或跨浏览器问题时存在问题...

从缓存中提取它不是问题,因为实际文件并没有改变,它只需要重新加载。

这会是一个 ajax 任务吗? 我该怎么做呢?

提前致谢。

最佳答案

function foo(){
    $.getScript( url, function(script, textStatus, jqXHR){
        script...
    });
}

setInterval(foo, 30000);

Caching Responses

Be default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested.

关于javascript - 定时 Javascript 文件刷新而不重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11004113/

相关文章:

javascript - 无需ajax或iframe的回调(纯代码)

jQuery 插件 : Get the "this" object inside other functions

javascript - Angular 2 : [hidden] and *NgIf not working?

javascript - 替代 YUI3 中的 YUI 网格?

javascript - dom操作-如何正确使用createElement?

javascript - 如何正确地将html表单数据编译为JSON对象

php - 使用 jquery 仅显示数据库中的最新行

jquery - AngularJS 和指令的初学者问题 - 包装 jQuery 组件

jquery - 通过 event.preventDefault() 阻止表单提交;不工作

javascript - 全局配置所有 $.ajax 请求以支持超时重试