I'm a little confusing of how I can wait ajax return values and then do something. Here what I tryed:
$('.project-item').on('click', function(){
var id = $(this).attr('id');
$.when(getImages(id)).done(function(resp) {
console.log(resp.responseJSON);
});
});
function getImages(id) {
var data = {
'action' : 'getImages',
'id' : id,
};
var result = $.Deferred();
result.resolve($.post(ajaxurl, data));
return result.promise();
}
But console.log(resp.responseJSON); immediattely return undefined;
The ajax call was tested before and is returning results.