I'm using jQuery $.when function to synchronize two $.getJSON asynchronous calls I have. Merging the data from both calls now works fine, however I want to return the contents of the merge , which is an array of jQuery objects.
I'm trying to achieve this using a $.when function wrapped around another function which contains the code where I synchronize my asynchronous calls. My code looks like this:
$.fn.getResultFromMergedJsonCalls = function(params){ $.when( $.fn.jsonCall1(params), $.fn.jsonCAll2(params) ).then(function(){ var mergedData = mergeResults(resultOfJsonCAll1,resultOfJsonCAll2) return mergedData; }); }; ) How can I return the contents of the mergedData array to a calling function , i know the nature of the asynchronous calls is causing this behavior so i just need a pattern that solves the problem. Thanks.
.then, or pass it to a function called from inside the callback.$.fnfunctions directly.