0

I have the following JavaScript/jQuery code:

setInterval(function() {
  $.getJSON('../0.json', function(json) {
    alert("piep");
    $.each(json, function(k, v) {
      $('.' + k).text(v.value);
    });
  });
}, 1000);

As you see, I'm trying to get a local JSON file and do something with it. To check whether the .getJSON function works, I let it alert me. Which is in fact the problem: it does not alert.

Currently, the page is static, but was part of a Sinatra app. In the app it got it from

'/0.json'

as the server served it thusly, and it worked.
Hence, I'm infering it having something to do with the "staticness" of the HTML page and the local JSON file.

Is it even possible to get local JSON files?

EDIT: The JSON file being a local one, the access is being forbidden by the browser.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
enlightened
  • 59
  • 2
  • 9
  • 1
    When you say "local files" are you referring to files on the client computer? In that case see [Local file access with javascript](http://stackoverflow.com/questions/371875/local-file-access-with-javascript) – Tomm Nov 17 '11 at 21:38
  • Are you running your page on any kind of a server, or just open it in browser? In latter option, it would not work, because of CORS. – madhead Nov 17 '11 at 21:40
  • Yeah, just opening the .html. Heard about these restrictions ... giving up and switching back to the server solution now. Thank you anyway! – enlightened Nov 17 '11 at 21:44

1 Answers1

0

I'm guessing you're using Chrome. There's a restriction in Chrome on accessing any files via xhr requests starting with file://.

There's more info here http://www.google.com/support/forum/p/Chrome/thread?tid=171316324d16747b&hl=en

Geuis
  • 41,122
  • 56
  • 157
  • 219