Reputation: 11
I've been trying to figure out why the code below isn't working and I am not having any success, even though it appears to be very simple and straightforward. Your help is much appreciated.
$.getJSON('http://67.224.83.133/Data/test.json', function (data) {
$.each(data.person, function(i, v) {
if (v.name == "Peter") {
alert(v.age);
return;
}
});
});
Thanks, Vic
Upvotes: 1
Views: 112
Reputation: 33875
It looks like you are doing a cross-domain request, since you are calling an IP-address. That is not allow to do with regular JSON. You will need to use JSON-P on cross-domain requests, or you can create a server-side proxy, that you can send your request to, within your own domain. The proxy will work as a "middle man", requesting the JSON from the source, and then pass it to your JavaScript from within your own domain.
Upvotes: 2