0

I am trying to access JSON data from separate json file(in different folder)but it is throwing exception " No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. "

I have my file at root "Index.html".Parallel to this there is a separate folder "JSON" which contains my json file "quotes.json". My Code is

$(document).on("pagebeforeshow", "#info-page", function () {
    $.getJSON("Json/quotes.json", function (data) {
        var items = [];
        $.each(data, function (key, val) {
            items.push(val);
            alert(data.key);
        });      
    });
});
F11
  • 3,703
  • 12
  • 49
  • 83
  • try to change the extension of the file: .getJSON("Json/quote.html", etc .. – PaolaG Feb 24 '14 at 07:24
  • Your code is suffering [`CORS`(cross domain issue)](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing). see [this](http://stackoverflow.com/a/19866904/1671639) or try to use `jsonp` dataType. – Praveen Feb 24 '14 at 07:29
  • 1
    cors doesn't make sense on local paths; use get() instead of getJSON()... – dandavis Feb 24 '14 at 07:33
  • json file name is quotes.json.Updated it in question – F11 Feb 24 '14 at 08:06

1 Answers1

0

You need to create a json file with name quotes.json instead of quotes.html and put your json code inside this file.

Felix
  • 37,892
  • 8
  • 43
  • 55
  • Actually, I just follow OP's question which I'm assuming he's testing on the localhost. – Felix Feb 24 '14 at 07:37