XMLHttpRequest无法在Google Chrome打包的Web应用程序中使用 [英] XMLHttpRequest not working in Google Chrome Packaged Web App
问题描述
我正在编写一个打包的 Chrome Web应用,并尝试解析外部XML。它在我将XML文件下载到服务器时起作用,但在将XML文件更改为网上位置时无效。
例如,我尝试访问此文件: http://www.w3schools.com/xml/note.xml
这是我的JavaScript代码(注意HTML):
function dashboardContent(){
html =;
xmlhttp = new XMLHttpRequest();
xmlhttp.open(GET,http://www.w3schools.com/xml/note.xml,false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
html + = xmlDoc.getElementsByTagName(to)[0] .childNodes [0] .nodeValue;
html + = xmlDoc.getElementsByTagName(from)[0] .childNodes [0] .nodeValue;
html + = xmlDoc.getElementsByTagName(body)[0] .childNodes [0] .nodeValue;
document.getElementById(contentArea)。innerHTML = html;
}
在我的Chrome Web应用程序manifest.json文件中,根据Google的跨源XMLHttpRequests清单要求, :
{
name:BirdTrax,
version:0.1.1 ,
description:探险探险家可帮助您计划观鸟旅行并在您所在地区查找最近eBirded的目击,稀有物品和清单,
图标:{
16:icons / helloWorld_16.png,
128:icons / helloWorld_128.png
},
app:{
launch:{
local_path:main.html,
container:tab
}
},
background_page:background.html,
options_page:options.html,
权限:[
http:// www.w3schools.com/*,
notifica tions,
unlimitedStorage
],
隐身:拆分
我不确定我是否还遗漏了一些东西,但是这些代码并不适合我。任何建议,提示,想法?我非常感谢任何帮助!
只需在 /
。否则,您只允许您的扩展程序仅在请求根页面。
permissions :[
http://www.w3schools.com/*,
在你的情况,你只需要一个URL。限制这种模式可能更好:
permissions:[
http:// www.w3schools.com/xml/note.xml,
I'm writing a packaged Chrome Web App and trying to parse external XML. It works when I download the XML file to my server, but does not work when I change the XML file to the location on the web.
For example, I am trying to access this file: http://www.w3schools.com/xml/note.xml
Here is my JavaScript code (note that HTML ):
function dashboardContent() {
html="";
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","http://www.w3schools.com/xml/note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
html+=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
html+=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
html+=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
document.getElementById("contentArea").innerHTML=html;
}
In my Chrome Web App manifest.json file, I put the following under permissions per Google's manifest requirement for Cross-origin XMLHttpRequests:
{
"name": "BirdTrax",
"version": "0.1.1",
"description": "Birding explorer to help you plan birding trips and find recently eBirded sightings, rarities, and checklists in your area",
"icons": {
"16": "icons/helloWorld_16.png",
"128": "icons/helloWorld_128.png"
},
"app": {
"launch": {
"local_path": "main.html",
"container": "tab"
}
},
"background_page": "background.html",
"options_page": "options.html",
"permissions": [
"http://www.w3schools.com/*",
"notifications",
"unlimitedStorage"
],
"incognito": "split"
}
I'm not sure if I'm still missing something, but the code isn't working for me. Any suggestions, tips, ideas? I really appreciate any help!!
Suffice a wildcard after /
. Otherwise, you're allowing your extension to only request pages at the root.
"permissions": [
"http://www.w3schools.com/*",
In your case, you're requesting only one URL. It might be even better to restrict the pattern even more:
"permissions": [
"http://www.w3schools.com/xml/note.xml",
这篇关于XMLHttpRequest无法在Google Chrome打包的Web应用程序中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!