使用 javascript 从 github 页面服务器读取 Json 文件
Reading Json file from github pages server using javascript
我正在 github 页面上构建我的网站,这些页面只能托管静态网站。但是它确实允许使用 javascript。所以我在我的网站运行的 github 服务器上有一个 json 文件,我想使用 javascript 获取和处理它。文件的 link 在
下面
https://bioinfobot.github.io/data/2017-05.json
更具体地说,它位于 data/2017-05。json
如果你点击上面的link,它会显示我的json文件的属性。
我尝试了堆栈交换的许多调整,但没有任何效果。有人可以给我一个简单的代码来调用这个文件到一个对象。我可以从那里做剩下的事。谢谢
您可以尝试使用 jquery
$.getJSON("https://bioinfobot.github.io/data/2017-05.json")
.done(function( data ) {
console.log(data)
});
或
$.getJSON("https://bioinfobot.github.io/data/2017-05.json", function(json) {
console.log(json);
});
$(function(){
$.getJSON("https://bioinfobot.github.io/data/2017-05.json",function(data)
{console.log(data)});
})();
只需提出要求:
fetch('https://bioinfobot.github.io/data/2017-05.json')
.then(res => res.json())
.then(json => {
//json vaiable contains object with data
})
我正在 github 页面上构建我的网站,这些页面只能托管静态网站。但是它确实允许使用 javascript。所以我在我的网站运行的 github 服务器上有一个 json 文件,我想使用 javascript 获取和处理它。文件的 link 在
下面https://bioinfobot.github.io/data/2017-05.json
更具体地说,它位于 data/2017-05。json
如果你点击上面的link,它会显示我的json文件的属性。
我尝试了堆栈交换的许多调整,但没有任何效果。有人可以给我一个简单的代码来调用这个文件到一个对象。我可以从那里做剩下的事。谢谢
您可以尝试使用 jquery
$.getJSON("https://bioinfobot.github.io/data/2017-05.json")
.done(function( data ) {
console.log(data)
});
或
$.getJSON("https://bioinfobot.github.io/data/2017-05.json", function(json) {
console.log(json);
});
$(function(){
$.getJSON("https://bioinfobot.github.io/data/2017-05.json",function(data)
{console.log(data)});
})();
只需提出要求:
fetch('https://bioinfobot.github.io/data/2017-05.json')
.then(res => res.json())
.then(json => {
//json vaiable contains object with data
})