[Solved] storing AJAX response into variable for use later in script?


From what I understand (see comments) you are dealing with a typical problem with asynchronous calls. You call AJAX, then you call setupGraph() but the ajax response will arrive after that call, because it is asynchronous.

First of all, doing async: false is bad, wrong and the source of all evil. Don’t use it never ever. In your case it won’t even work, because you can’t force JSONP to be synchronous. But even if you could let me repeat my self, because this is important: don’t ever use async: false.

Now back to your problem. What you should is to use deferred callbacks instead:

var reqs = [];
$('.inp').each(function(){
    // some code
    reqs.push(
        $.ajax({
            // some settings
        })
    );
});

$.when.apply($, reqs).then(function() {
    setupGraph();
});

Read more about $.when here: https://api.jquery.com/jQuery.when/

1

solved storing AJAX response into variable for use later in script?