Sredny M Casanova
Sredny M Casanova

Reputation: 5063

retrieving data from Json with Jquery

I'm trying to use Jquery to get the attributes of a Json variable. I made an ajax request with:

 $.ajax({ 
       url: 'myURL/' + id + '/' + date, 
       dataType: 'json', 
 }).done(function (data) {}

I put the url in the browser,and the returned data is like:

{"pico":0,"valle":1,"administrativas":"0"} 

So, inside de done function how I get the value of pico variable for example?

Upvotes: 1

Views: 36

Answers (3)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167250

Just make it simple using:

$.ajax({
    url: 'myURL/' + id + '/' + date, 
    dataType: 'json',
    success: function (data) {
        alert(data.pico);
    }
});

Upvotes: 1

JToTheC
JToTheC

Reputation: 313

By accessing the property in the data response:

var data = {"pico":0,"valle":1,"administrativas":"0"};
console.log(data.pico);

Upvotes: 1

Manuel Garcia
Manuel Garcia

Reputation: 144

$.ajax({ 
   url: 'myURL/' + id + '/' + date, 
   dataType: 'json', 
}).done(function (data) {
 console.log(data.pico);
}

Upvotes: 1

Related Questions