1

I'm trying to follow this tutorial: http://www.9lessons.info/2009/10/json-jquery-ajax-php.html

Here is my code: http://jsfiddle.net/9ujd8s8r/1/

How comes that it doesn't load the JSON data into the page with this code?

$(function () {
    $(".load").click(function () {
        $.getJSON("http://demos.9lessons.info/data.json", function (data) {
            $.each(data.posts, function (i, data) {
                var div_data = "<div class='box'><a href='" + data.url + "'>" + data.title + "</a></div>";

                $(div_data).appendTo("#9lessonsLinks");
            });
        });
        return false;
    });


});
2
  • You have not define "9lessonsLinks" id anywhere in the html. define it. due to that your data is not populating. Commented Sep 12, 2014 at 13:40
  • By the way, mentioned site has awful code indentation. To be honest, it doesn't have code indentation at all... Commented Sep 12, 2014 at 13:40

2 Answers 2

1

Check your console for errors. The following error is showing:

XMLHttpRequest cannot load http://demos.9lessons.info/data.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.

For more information see "No 'Access-Control-Allow-Origin' header is present on the requested resource".

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

Comments

0

Your code seems correct. It's a problem of crossdomain. You try to access resource in another server which has not defined that you can.

http://jquery-howto.blogspot.fr/2013/09/jquery-cross-domain-ajax-request.html

3 Comments

Note: JSONP won't help here as the server doesn't provide a JSONP service.
Yes but there is 5 other methods which can maybe help
Yes, and I was simply pointing out that one of them won't work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.