i have ajax call several different services. know array var log
being overwritten each successive call, can't figure out how change logic append next array instead of overwriting.
$.ajax($.extend({}, ajaxdefaults, source, { data: data, success: function(events) { events = events || []; var res = applyall(success, this, arguments); if ($.isarray(res)) { events = res; } callback(events); var log = log || []; (var i=0; i<events.length; i++) { log.push(events[i]); } console.log(log); }, error: function() { applyall(error, this, arguments); callback(); }, complete: function(events) { applyall(complete, this, arguments); poploading(); } }));
this problem of scope. you're redeclaring 'var log' inside of $.ajax success() function (and overwriting it). declare var log outside of $.ajax , push new results array.
try following:
var log = []; $.ajax($.extend({}, ajaxdefaults, source, { data: data, success: function(events) { events = events || []; var res = applyall(success, this, arguments); if ($.isarray(res)) { events = res; } callback(events); (var i=0; i<events.length; i++) { log.push(events[i]); } console.log(log); }, error: function() { applyall(error, this, arguments); callback(); }, complete: function(events) { applyall(complete, this, arguments); poploading(); } }));