retrieve value in unnamed json array url retrieve value in unnamed json array url json json

retrieve value in unnamed json array url


That would be something like :

$.getJSON("http://go-gadget.googlecode.com/svn/trunk/test.json", function(json) {    for (var i = 0; i < json.length; i++) {        var map     = json[i].propertyMap;        var content = map.content;        var user    = map.user;        var date    = map.date;        $('#date').text(date);        $('#nohp').text(user);        $('#content').text(content);    }});

But the request fails, as no 'Access-Control-Allow-Origin' header is present on the requested resource, so you're being stopped by the same origin policy


What do you think [].length; would evaluate to .

It is 0 , so it would never go inside the for loop.

Other than that you code looks ok.

Replace your for loop as below

$.getJSON(url, function (json) {    for (var i = 0; i < json.length; i = i + 1) {

Also you seem to be accessing a API as part of the different domain.So you need to use CORS or JSONP to get this working if you want to retrieve data from a different domain.


Change:

for (var i = 0; i < [].length; i = i + 1) {

to

for (var i = 0; i < json.length; i = i + 1) {

DEMO here.