Is it possible to set async:false to $.getJSON call

ACP picture ACP · May 4, 2010 · Viewed 121.9k times · Source

Is it possible to set async: false when calling $.getJSON() so that the call blocks rather than being asynchronous?

Answer

Nick Craver picture Nick Craver · May 4, 2010

You need to make the call using $.ajax() to it synchronously, like this:

$.ajax({
  url: myUrl,
  dataType: 'json',
  async: false,
  data: myData,
  success: function(data) {
    //stuff
    //...
  }
});

This would match currently using $.getJSON() like this:

$.getJSON(myUrl, myData, function(data) { 
  //stuff
  //...
});