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

    <tfoot id='OgZXh'></tfoot>
      • <bdo id='OgZXh'></bdo><ul id='OgZXh'></ul>
    1. <legend id='OgZXh'><style id='OgZXh'><dir id='OgZXh'><q id='OgZXh'></q></dir></style></legend>

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

      1. 在 Chrome 打包应用程序中通过 XHR 加载本地内容

        时间:2023-10-13
          • <tfoot id='aeB0S'></tfoot>

                <tbody id='aeB0S'></tbody>
              <legend id='aeB0S'><style id='aeB0S'><dir id='aeB0S'><q id='aeB0S'></q></dir></style></legend>

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

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

                  <i id='aeB0S'><tr id='aeB0S'><dt id='aeB0S'><q id='aeB0S'><span id='aeB0S'><b id='aeB0S'><form id='aeB0S'><ins id='aeB0S'></ins><ul id='aeB0S'></ul><sub id='aeB0S'></sub></form><legend id='aeB0S'></legend><bdo id='aeB0S'><pre id='aeB0S'><center id='aeB0S'></center></pre></bdo></b><th id='aeB0S'></th></span></q></dt></tr></i><div id='aeB0S'><tfoot id='aeB0S'></tfoot><dl id='aeB0S'><fieldset id='aeB0S'></fieldset></dl></div>
                  本文介绍了在 Chrome 打包应用程序中通过 XHR 加载本地内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试加载使用 Backbone 构建的 Web 应用程序,它会提取本地存储的 JSON 和 HTML 模板文件.我想知道 Chrome 打包应用是否可以通过使用某种get"/ajax 请求来加载这些文件?

                  I'm trying to load in a web app that I've built using Backbone and it pulls in JSON and HTML template files that are stored locally. I was wondering with Chrome packaged apps whether it's possible to load these files by using some sort of 'get'/ajax request?

                  目前我正在接受这个......

                  Currently I'm getting this...

                  OPTIONS chrome-extension://fibpcbellfjkmapljkjdlpgencmekhco/templates/templates.html Cannot make any requests from null. jquery.min.js:2
                  XMLHttpRequest cannot load chrome-extension://fibpcbellfjkmapljkjdlpgencmekhco/templates/templates.html. Cannot make any requests from null.
                  

                  我找不到任何有关如何执行此操作的真实信息,因此非常感谢您的帮助!

                  I can't find any real information on how to do this so any help would be great thanks!

                  推荐答案

                  是的,这完全有可能,而且很简单.这是一个工作示例.尝试从这个开始,确认它有效,然后添加回您自己的代码.如果您遇到障碍并想出一个比 XHR 是否适用于打包应用程序更具体的问题,您可能想问一个新问题.

                  Yes, it's totally possible, and it's easy. Here's a working sample. Try starting with this, confirm that it works, and then add back in your own code. If you hit a roadblock and come up with a more specific question than whether XHRs work in packaged apps, you might want to ask a new question.

                  manifest.json:

                  manifest.json:

                  {
                    "name": "SO 15977151 for EggCup",
                    "description": "Demonstrates local XHR",
                    "manifest_version" : 2,
                    "version" : "0.1",
                    "app" : {
                      "background" : {
                        "scripts" : ["background.js"]
                      }
                    },
                    "permissions" : []
                  }
                  

                  background.js:

                  background.js:

                  chrome.app.runtime.onLaunched.addListener(function() {
                    chrome.app.window.create("window.html",
                      { bounds: { width: 600, height: 400 }});
                  });
                  

                  window.html:

                  window.html:

                  <html>
                  <body>
                    <div>The content is "<span id="content"/>"</div>
                    <script src="main.js"></script>
                  </body>
                  </html>
                  

                  main.js:

                  function requestListener() {
                    document.querySelector("#content").innerHTML = this.responseText;
                  };
                  
                  onload = function() {
                    var request = new XMLHttpRequest();
                    request.onload = requestListener;
                    request.open("GET", "content.txt", true);
                    request.send();
                  };
                  

                  内容.txt:

                  Hello, world!
                  

                  这篇关于在 Chrome 打包应用程序中通过 XHR 加载本地内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:实例化 XMLHttpRequest 对象的最佳方法 下一篇:jQuery $.ajax 或 $.load 是否允许 responseType arrayBuffe

                  相关文章

                  最新文章

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

                      • <bdo id='RLKJb'></bdo><ul id='RLKJb'></ul>
                      <legend id='RLKJb'><style id='RLKJb'><dir id='RLKJb'><q id='RLKJb'></q></dir></style></legend>

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

                      <tfoot id='RLKJb'></tfoot>