I have this code below, which is supposed to return the result of the call. I need to do this synchronously so that I know everything is good, however it doesn\'t seem to work.
getJSON does not honor async:false
getJSON has no async: false
option. You'd have to use ajax for that.
According to the documentation, getJSON
is equivalent to:
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
...to which you can easily add an async: false
option (for now, be forewarned that jQuery will be dropping support for that).
I need to do this synchronously so that I know everything is good
You don't need to do anything synchronously to "know everything is good", it's perfectly possible (and normal) to handle results (whether "good" or errors) asynchronously.
In the comments on your question, you've written:
jsonp? This is the code I am using.
JSON-P is not the same as JSON (and getJSON
doesn't do JSON-P unless you have callback=?
or similar in the URL), and JSON-P is inherently asynchronous. Unlike a true ajax call via XMLHttpRequest
, it's impossible to make JSON-P synchronous.