javascript - XMLHttpRequest not working in Google Chrome Packaged Web App -
i'm writing packaged chrome web app , trying parse external xml. works when download xml file server, not work when change xml file location on web.
for example, trying access file: http://www.w3schools.com/xml/note.xml
here javascript code (note 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 chrome web app manifest.json file, put following under permissions per google's manifest requirement cross-origin xmlhttprequests:
{ "name": "birdtrax", "version": "0.1.1", "description": "birding explorer plan birding trips , find ebirded sightings, rarities, , checklists in 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, code isn't working me. suggestions, tips, ideas? appreciate help!!
suffice wildcard after /
. otherwise, you're allowing extension only request pages @ root.
"permissions": [ "http://www.w3schools.com/*",
in case, you're requesting 1 url. might better restrict pattern more:
"permissions": [ "http://www.w3schools.com/xml/note.xml",
Comments
Post a Comment