use*_*227 2 ajax jquery json refresh
我编写了代码来获取JSON文件并对其进行处理.但该文件每5分钟更新一次.所以我希望我的代码能够在不引起刷新的情况下获取新数据.
这是我如何获取JSON文件.
$.getJSON("new_json_file.json", function (data) {
$.each(data, function (i, item) {
//Here I am working on the data
});
});
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
将代码包装在一个函数中,然后它可以用来setTimeout在5分钟后再次运行自己...
function getData() {
$.getJSON("new_json_file.json", function (data) {
$.each(data, function (i, item) {
//Here I am working on the data
});
setTimeout(getData, 300000);
});
}
getData(); // run once to start it
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1670 次 |
| 最近记录: |