0

I have a function that makes a $.getjson request and callbacks another function to use the results.

What Id like to do is call the functions twice and store the results in variable and use those 2 variables to do something. How would I go about this?

looks something like this

function getData(selection, callback){
  $.getJSON(url, selection, function(data){
    callback(data)
  });
}

function doSomething(data){
  return data + 2
}

then I want to store that data in a variable BUT call getData and callback twice and store results in different variables to do something with. Like:

a = getData("selection1", doSomething)
b = getData("selection2", doSomething)

console.log(a+b)
dustin
  • 47
  • 6
  • does the order of calling/getting results matter, or you just need two get the two results and compare them? – Marc B Nov 20 '15 at 20:10
  • I just need two get the two results and compare them. – dustin Nov 20 '15 at 20:13
  • then have one common callback success function for both calls. it can keep track of how many times it's been called - 1st call, store result. 2nd call - compare new result against stored result. – Marc B Nov 20 '15 at 20:17

0 Answers0