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);
        });      
    });
});
4
  • try to change the extension of the file: .getJSON("Json/quote.html", etc .. Commented Feb 24, 2014 at 7:24
  • Your code is suffering CORS(cross domain issue). see this or try to use jsonp dataType. Commented Feb 24, 2014 at 7:29
  • 1
    cors doesn't make sense on local paths; use get() instead of getJSON()... Commented Feb 24, 2014 at 7:33
  • json file name is quotes.json.Updated it in question Commented Feb 24, 2014 at 8:06

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, I just follow OP's question which I'm assuming he's testing on the localhost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.