Mohan Ram
Mohan Ram

Reputation: 8463

jquery getJSON not working on url

I had found json url for live display of scores

http://json-cricket.appspot.com/score.json

Output of json:

{
 "batting_team": "Canada", "date": "Feb 28, 2011",
 "match": "Canada vs Zimbabwe", "score": "Canada 106-8 (37)",
 "summary": "Z Surkari(21) H Baidwan(3)*" 
}

I don't know how to fetch and display the data in my site I am using following codes:

$.getJSON("http://json-cricket.appspot.com/score.json", function (data) {
    $.each(data, function (i, set) {
        alert("Batting Team: "+set.batting_team);
    });
});

Please mention me what wrong I did. I can't get the data from json. I am not being able to connect to the site.

Thanks in advance

Upvotes: 3

Views: 4799

Answers (2)

Mohan Ram
Mohan Ram

Reputation: 8463

Hey I Fetched cricket score using this,

var url="http://json-cricket.appspot.com/score.json?callback=?";
$.getJSON(url, function (data) {
    for(var item in data) {
        alert(item + ':' + data[item]);
    }
});

Upvotes: 2

Neil
Neil

Reputation: 5782

You probably mean to do something more like:

for(var item in data) {
    alert(item + ':' + data[item]);
}

This gives you messages like "batting_team : Canada" and "date : Feb 28, 2011" which is probably more what you want.

Upvotes: 2

Related Questions