I have a JavaScript class that has a method:
function someClass() {
this.someMethod = someClass_someMethod;
}
function someClass_someMethod() {
// make an AJAX request
}
The problem is that someClass_someMethod() needs to return the value of the AJAX request.
I’m using jQuery’s $.getJSON() method to fetch the data. The data needs to be returned but it seems the only way to get the data is through a callback.
How can this be done?
You could use a non async request, but that ties up the browser whilst the request is in action.
Callback is really the only way, as you need to wait any arbitrary amount of time for the request to either succeed or error.