2017-05-31 93 views
0

我在只能托管静态网站的github页面上构建我的网站。但它确实允许使用JavaScript。所以我在我的网站运行的github服务器上有一个json文件,我想使用javascript获取并处理它。该文件的链接低于从Github页面服务器使用javascript读取Json文件

https://bioinfobot.github.io/data/2017-05.json

确切地说,是位于数据/ 2017-05.json

如果您点击链接上面,它会显示我的JSON文件的属性。

我尝试了很多来自堆栈交换的调整,但没有任何工作为我。有人可以给我一个简单的代码来调用这个文件到一个对象。我可以从那里休息。谢谢。

回答

2

你可以试试这个使用jQuery

$.getJSON("https://bioinfobot.github.io/data/2017-05.json") 
    .done(function(data) { 
     console.log(data) 
    }); 

OR

$.getJSON("https://bioinfobot.github.io/data/2017-05.json", function(json) { 
    console.log(json); 
}); 
0
$(function(){ 
    $.getJSON("https://bioinfobot.github.io/data/2017-05.json",function(data) 
    {console.log(data)}); 
})(); 
0

只是提出一个要求:

fetch('https://bioinfobot.github.io/data/2017-05.json') 
 
    .then(res => res.json()) 
 
    .then(json => { 
 
    //json vaiable contains object with data 
 
    })