javascript - XMLHttpRequest not working in Google Chrome Packaged Web App - Stack Overflow

I'm writing a packaged Chrome Web App and trying to parse external XML.It works when I download

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: .xml

Here is my JavaScript code (note that HTML ):

function dashboardContent() {
html="";

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",".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": [
  "/*",
  "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!!

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./xml/note.xml

Here is my JavaScript code (note that HTML ):

function dashboardContent() {
html="";

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","http://www.w3schools./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./*",
  "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!!

Share Improve this question edited Jul 7, 2012 at 14:45 zdebruine asked Jul 7, 2012 at 14:16 zdebruinezdebruine 3,8176 gold badges33 silver badges52 bronze badges 3
  • In which file is that script placed? How is the function called? – Rob W Commented Jul 7, 2012 at 14:47
  • @RobW The function is called when the <body> element loads. <body onload="dashboardContent()". The script linked in the <head> of my main.html document which loads as default first page. – zdebruine Commented Jul 7, 2012 at 14:50
  • I think I'll just copy Google's own example code and try to work from there. Thanks for your help! – zdebruine Commented Jul 7, 2012 at 15:00
Add a ment  | 

1 Answer 1

Reset to default 3

Suffice a wildcard after /. Otherwise, you're allowing your extension to only request pages at the root.

"permissions": [
  "http://www.w3schools./*",

In your case, you're requesting only one URL. It might be even better to restrict the pattern even more:

"permissions": [
  "http://www.w3schools./xml/note.xml",

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信