从github文件加载json [英] Load json from github file

查看:509
本文介绍了从github文件加载json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从由github页面托管的网页访问/检索一些json数据,因此我的所有文件都在我的存储库中。



我试图做

$ $ p $ $ getJSON( https://raw.githubusercontent.com/mydata.json,函数(data){
console.log(data);
}


,因为这是我现在知道如何访问json数据的唯一方法。但是,json内容位于域 https://raw.githubusercontent.com ,而我的网页来自域 http://mygithub.github.io ,所以我得到了一个'Access-Control-Allow-Origin'错误,即使数据至少都在同一个地方托管?



关于如何解决这个问题或解决这个问题的想法?我一直在寻找一些CORS的东西,但没有完全理解它,也没有如何改变任何与github相关的东西。

谢谢!

解决方案

http://mygithub.github.io/mydata.json



githubusercontent.com 很慢并且不会为json text-plain 而不是 application / json


I'm trying to access/retrieve some json data from a webpage hosted by github pages, so all of my files are within my repository.

I'm trying to do

$.getJSON("https://raw.githubusercontent.com/mydata.json", function(data){
      console.log(data);
}

from my html page on github-pages, since that's the only way I know how to access the json data right now. However, The json content is on the domain https://raw.githubusercontent.com while my page is from the domain http://mygithub.github.io, so I'm getting a 'Access-Control-Allow-Origin' error, even though the data is all hosted on the same place at least?

Any ideas on how to fix that, or get around that? I've been looking up some CORS stuff but don't completely understand it, nor how to change anything related to that on github.

Thanks!

解决方案

Why don't you simply call http://mygithub.github.io/mydata.json ?

githubusercontent.com is slow and doesn't return the correct mime type for json text-plain instead of application/json.

这篇关于从github文件加载json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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