returning JSON values (objects) via ajax
Suppose i have a json file like this:
{
"content": {
"statistics": [
{
"key": "aaaa",
"value": {
"hits": 0,
"misses": 0,
"errors": 0,
"hitRate": 0.0
}
},
{
"key": "bbbb",
"value": {
"hits": 0,
"misses": 0,
"errors": 0,
"hitRate": 0.0
}
},
{
"key": "cccc",
"value": {
"hits": 0,
"misses": 0,
"errors": 0,
"hitRate": 0.0
}
}
],
"enabled": false
},
"meta": {
"httpCode": 000
}
}
and using this ajax:
$.ajax({
type: "GET",
url: url,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
dataType: "json",
success: function(data){
console.log(data);
var key=data["key"];
console.log(key);
}
});
}
but this code above does not work, it doesn't return keys from the json.
How do I display out all the values for keys, values, hits..etc? Many
thank for your help
No comments:
Post a Comment