I’m have trouble grabbing the response JSON data that’s returned via AJAX call. Here is what I’m getting back in firebug.
{"COLUMNS":["ID","NAME","REGION","EMAIL"],"DATA":[["1234","John Doe","West","johndoe@mydomain.com"]]}
Here is my script:
$.ajax({
url: "action.cfc?method=getEmployees&returnformat=json&queryFormat=column", type: "POST",
success: function(response){
console.log(response);// is the data above
console.log(response.DATA.NAME[1]); // this doesn’t work
console.log(response.DATA['NAME']);//and this doesn’t work
}
});
I’m getting this error in fireBug “response.DATA is undefined” when trying to console log the name. What am I missing? Thank in advance for your help!
response.DATAis an array of arrays so you need to index each level.EDIT: if you want to use key/value pairings you would need to create a
structin CF instead of arrayYou should also set dataType:’json’ in $.ajax