I have the following ajax call and the json feed it returns. how do I get the value of the data object i.e. FRI from the feed using jquery?
$.ajax({
url: query,
type: "GET",
dataType: "json"
success: function(data) {
var day = // get data value from json
$("#Day").val(day);
}
});
{
"name":"workdays",
"columns":[
"day"
],
"data":[
[
"FRI"
]
]
}
* update *
What would be the syntax be if the results were returned as jsonp as follows, how can you extract the value 'FRI' :
import({
"Results":{
"work_days":{
"empid":100010918994,
"day":"FRI"
}
}
});
This is just JavaScript, not jQuery.
var data = {
"name":"workdays",
"columns":[
"day"
],
"data":[
[
"FRI"
]
]
}
data.data[0][0]; //FRI
UPDATE
var obj = {
"Results":{
"work_days":{
"empid":100010918994,
"day":"FRI"
}
}
}
obj.Results.work_days.day //FRI
If the latter json is the json you get from the server, you can get the data like this:
var day = data.data[0][0];
This will put the value FRI
in the variable day
.
EDIT: If you use a recent browser, you can always do console.log(data)
and look in your javascript console what is in the variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With