javascript - Reading code from GitHub as text (raw) in a web page - Stack Overflow

I'm trying to read some source code (C language) from my GitHub repository to be shown as text in

I'm trying to read some source code (C language) from my GitHub repository to be shown as text in my webpage. I can access the code in raw mode through .

I'm using jQuery GET function to read the data but it doesn't work. Problem is related with XMLHttpRequest and Access-Control-Allow-Origin but, despite I found some related question on stackoverflow (XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin) it didn't work for me. I tried everything.

My jQuery code:

<script type="text/javascript">
  $(document).ready(function() {
    var url = '.c';

    $.get(url, function(data) { 
        $('#code').text(data);
      }, 'text');
    });
</script>

Please, could someone help me with this issue? Many thanks!

I'm trying to read some source code (C language) from my GitHub repository to be shown as text in my webpage. I can access the code in raw mode through https://raw.github..

I'm using jQuery GET function to read the data but it doesn't work. Problem is related with XMLHttpRequest and Access-Control-Allow-Origin but, despite I found some related question on stackoverflow (XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin) it didn't work for me. I tried everything.

My jQuery code:

<script type="text/javascript">
  $(document).ready(function() {
    var url = 'https://raw.github./raysan5/raylib/master/examples/ex01_basic_window.c';

    $.get(url, function(data) { 
        $('#code').text(data);
      }, 'text');
    });
</script>

Please, could someone help me with this issue? Many thanks!

Share Improve this question edited May 23, 2017 at 12:12 CommunityBot 11 silver badge asked Nov 23, 2013 at 11:21 RayRay 1332 silver badges9 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

2013: You could try and delete the dot between raw and github:

https://rawgithub./raysan5/raylib/master/examples/ex01_basic_window.c

See rawgithub., also explained in this blog post:

GitHub discourages this, since they want repo owners to use Github Pages to host specific versions of their files. They discourage it by serving files from the “raw” domain with Content-Type: text/plain instead of Content-type:application/javascript.

This wasn’t a problem until recently, when Google Chrome implemented a security fix that prevents JavaScript from being executed if it has an incorrect Content-type.
This makes sense when you’re viewing pages outside of your control. But when it’s you who’s deciding what scripts to include, it’s a hassle.

As Rob W ments below:

It's worth mentioning that the only reason that this web service solves the OP's problem is that it includes the Access-Control-Allow-Origin: * response header.


OCt. 2018: As seen in their homepage

RawGit has reached the end of its useful life

RawGit is now in a sunset phase and will soon shut down. It's been a fun five years, but all things must end.

GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served.

His creator, Ryan Grove, said Aug. 5th, 2023:

About 5 years ago I put RawGit into “sunset” mode. I generated a bloom filter representing every repo URL that had been active within the last month, deployed a change to only serve requests for those repos, resolved to let it keep running until it broke, and then never looked at it again except to renew the domain from time to time.

Checked on it today and it’s still running fine, serving 393 million requests and 4.1 TB of data a month with literally zero maintenance.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744389261a4571823.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信