Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am currently trying to parse a local JSON file on Webkit browsers and I am running into a couple issues.

var request = new XMLHttpRequest(); 
request.open('Get', 'file:///abc/test.json', false); 
var test = JSON.parse(request.responseText);

This however doesn't seem to work in Webkit Browsers (I am only testing on Webkit Browsers such as Chromium on ubuntu).

Could someone please help me point out what I might be doing wrong? Thank you in advance!

Edit: I noticed a bunch of responses indicate it isn't possible to use Ajax. Is there anything else I can use such as JQuery or do this?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The problem is that webkit doesn't allow ajax requests to file:/// So you have to use a http server which serves the site and the ajax response.

share|improve this answer
    
Any other suggestions? I realized that it isnt possible using Ajax, is there something else you would recommend to use to load up the JSON file with? –  Bilzac Oct 11 '11 at 18:57
3  
You can add the "json file" using the script tag (<script src="file.js">). In the Javascipt file you just write something like var data = "your json". Then you can use the data variable. –  styrr Oct 11 '11 at 19:52

Have you tried launching chrome with --allow-file-access-from-files key?
Seems to be related with Problems with jQuery getJSON using local files in Chrome question and Local files doesn't load with Ajax bug report.

share|improve this answer
    
Any other suggestions? I realized that it isnt possible using Ajax, is there something else you would recommend to use to load up the JSON file with? –  Bilzac Oct 11 '11 at 19:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.