I have a ajax request within an each() loop.
My first issue was that code outside of the each loop was executing prior to the each() loop completing (async).
I resolved this with the approach mentioned here: https://stackoverflow.com/a/17904856/1560199
The each loop now pushes each ajax response Object to the array, and once complete proceeds as required.
The problem I have is that I can't seem to use responseJSON directly on the ajax Object:
$comment_response_array = [];
$.each($message_id_array, function(message_key, message_id){
$comment_response_array.push($.fn.get_comments(message_id, $last_refresh).responseJSON);
});
The $.fn.get_comments eventually maps through the this ajax request:
$.fn.ajax_request = function($method, $ajax_file, $data) {
return $.ajax({
'type': $method,
'url': '../../ajax/' + $ajax_file + '.php',
'data': $data,
'dataType': "json"
});
};
With this, $comment_response_array
returns an array of undefined Objects.
Just looking for some guidance on whether I am taking the correct approach and just missing something simple, or if I need to change my approach any pointers would be appreciated.