I have following ajax function.
$.ajax({
url: "/ajax",
type: "get",
data: values ,
success: function (data) {
console.log(data); // This is Line 7
console.log(data[0].first_name); //// This is Line 8
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
Line 07 Output : [{"id":2,"first_name":"Nimalka","last_name":"Perera","address":"Kandy","age":25,"created_at":"2017-08-29 07:23:43","updated_at":"2017-08-29 07:23:43"}]
Line 08 Output : undefined
Why is line 08 undefined?
When I check the output with JSFiddle it works Fine. ( Link to the JsFiddle)
But why it is undefined in inside $.ajax function?
return json_encode($students);) why it getting as string?