I have this function which parses the JSON. I am getting undefined when I am calling it in a .live function.
Here is the function that I have created,
function getAbc() {
var details;
var id = $(this).attr('data-id');
$.ajax({
url : '/index.php/data',
type : 'GET',
data : 'persons[]=' + id,
success : function(data, textStatus, xhr) {
details = JSON.parse(data);
},
});
return details;
}
I am simply calling like this, getAbc(). And is there any way that I can access details variable in the function?
Use continuation passing style. The
$.ajaxis async in nature.