I need to set a variable to the results of an ajax query. I realise that i cannot just return result in the success function as this is an asynchronous call. but would like to achieve this will a callback function and not set to a synchronous call.
I would like to achieve something like:
myMethod: function() {
var result = function(callback) {
this.getResults(params)
}
},
getResults: function(params) {
$.ajax({
type: 'GET',
url: 'some/url',
data: params,
success: function(data) {
callback(data).call();
}
});
}
Where result = data
I know my syntax is not right, I have tried so many variations and havent found something that works. Any help would be soooooo appreciated. Thank-you!