• <tfoot id='n5fS5'></tfoot>

        <bdo id='n5fS5'></bdo><ul id='n5fS5'></ul>

      <legend id='n5fS5'><style id='n5fS5'><dir id='n5fS5'><q id='n5fS5'></q></dir></style></legend>

      <small id='n5fS5'></small><noframes id='n5fS5'>

      1. <i id='n5fS5'><tr id='n5fS5'><dt id='n5fS5'><q id='n5fS5'><span id='n5fS5'><b id='n5fS5'><form id='n5fS5'><ins id='n5fS5'></ins><ul id='n5fS5'></ul><sub id='n5fS5'></sub></form><legend id='n5fS5'></legend><bdo id='n5fS5'><pre id='n5fS5'><center id='n5fS5'></center></pre></bdo></b><th id='n5fS5'></th></span></q></dt></tr></i><div id='n5fS5'><tfoot id='n5fS5'></tfoot><dl id='n5fS5'><fieldset id='n5fS5'></fieldset></dl></div>

      2. 从 GitHub 读取代码作为网页中的文本(原始)

        时间:2023-10-13

            <tfoot id='bTrzn'></tfoot>
            <i id='bTrzn'><tr id='bTrzn'><dt id='bTrzn'><q id='bTrzn'><span id='bTrzn'><b id='bTrzn'><form id='bTrzn'><ins id='bTrzn'></ins><ul id='bTrzn'></ul><sub id='bTrzn'></sub></form><legend id='bTrzn'></legend><bdo id='bTrzn'><pre id='bTrzn'><center id='bTrzn'></center></pre></bdo></b><th id='bTrzn'></th></span></q></dt></tr></i><div id='bTrzn'><tfoot id='bTrzn'></tfoot><dl id='bTrzn'><fieldset id='bTrzn'></fieldset></dl></div>

                  <tbody id='bTrzn'></tbody>

                • <bdo id='bTrzn'></bdo><ul id='bTrzn'></ul>
                  <legend id='bTrzn'><style id='bTrzn'><dir id='bTrzn'><q id='bTrzn'></q></dir></style></legend>
                • <small id='bTrzn'></small><noframes id='bTrzn'>

                  本文介绍了从 GitHub 读取代码作为网页中的文本(原始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从我的 GitHub 存储库中读取一些源代码(C 语言),以便在我的网页中显示为文本.我可以通过 https://raw.github.com 以原始模式访问代码.

                  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.com.

                  我正在使用 jQuery GET 函数来读取数据,但它不起作用.问题与 XMLHttpRequest 和 Access-Control-Allow-Origin 有关,但是尽管我在 stackoverflow 上发现了一些相关问题(XmlHttpRequest 错误:Access-Control-Allow-Origin 不允许使用 Origin null)它对我不起作用.我什么都试过了.

                  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.

                  我的 jQuery 代码:

                  My jQuery code:

                  <script type="text/javascript">
                    $(document).ready(function() {
                      var url = 'https://raw.github.com/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!

                  推荐答案

                  你可以尝试删除raw和github之间的点:

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

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

                  参见 rawgithub.com,在这个 博文:

                  GitHub 不鼓励这样做,因为他们希望 repo 所有者使用 Github Pages 来托管其文件的特定版本.他们通过使用 Content-Type: text/plain 而不是 Content-type:application/javascript 提供来自raw"域的文件来阻止它.

                  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.

                  直到最近,当 Google Chrome 实施了一个安全修复程序,如果 JavaScript 的 Content-type 不正确,这将阻止 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.

                  作为 Rob W 以下评论:

                  值得一提的是,此网络服务解决 OP 问题的唯一原因是它包含 Access-Control-Allow-Origin: * 响应标头.

                  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.

                  这篇关于从 GitHub 读取代码作为网页中的文本(原始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用包含文件和发布数据的 JavaScript 创建 下一篇:如何在 firefox 插件中使用 Javascript 将图像上传到

                  相关文章

                  最新文章

                  <i id='sVxNw'><tr id='sVxNw'><dt id='sVxNw'><q id='sVxNw'><span id='sVxNw'><b id='sVxNw'><form id='sVxNw'><ins id='sVxNw'></ins><ul id='sVxNw'></ul><sub id='sVxNw'></sub></form><legend id='sVxNw'></legend><bdo id='sVxNw'><pre id='sVxNw'><center id='sVxNw'></center></pre></bdo></b><th id='sVxNw'></th></span></q></dt></tr></i><div id='sVxNw'><tfoot id='sVxNw'></tfoot><dl id='sVxNw'><fieldset id='sVxNw'></fieldset></dl></div>
                  • <bdo id='sVxNw'></bdo><ul id='sVxNw'></ul>

                • <small id='sVxNw'></small><noframes id='sVxNw'>

                  <legend id='sVxNw'><style id='sVxNw'><dir id='sVxNw'><q id='sVxNw'></q></dir></style></legend>

                    1. <tfoot id='sVxNw'></tfoot>