I am using jQuery's AJAX functionality - and I get a response back just fine, but for some odd reason I cannot parse the information inside of it!
I am calling the following:
console.log(results);
console.log(results.data);
And what I get is:
{"data":[{"member":"asdfasdf","status":"Invalid Email"}]}
undefined
Here is my jQuery:
$.ajax({
type: "POST",
url: "<?php echo Uri::base();?>ajax/add_members/organization",
data: {
organization_id: <?php echo $organization->id;?>,
members: $('#members').val(),
position: $('#position').val()
}
}).done(function (results) {
// lets add them to the table
console.log(results);
console.log(results.data);
});
UPDATE: dataType: 'json',
was required!
dataType
to be json. – Fabrício Matté Nov 29 '12 at 0:52dataType: 'json',
should ensure that jQuery automatically parses the response into an object. Likewise, using$.parseJSON
manually on the response (if it is a string) will also yield the same object. – Fabrício Matté Nov 29 '12 at 0:57Content-type: application/json
) and jQuery should be able to handle it automatically. – NullUserException♦ Nov 29 '12 at 0:57