For legacy reasons, a website is using JQuery 1.9.1.
I want to be able to create a function that returns data from a sync (not async) call using JQuery.
I do not want to use method chaining either given how the code is and the series of events that happen or the particular order of things. I simply want a standalone function I can call and it will, once the result comes back from the ajax call, return the data however it seems that when I try to do this, nothing comes back (too early?)
function GetLocation() {
var loc = "";
$.ajax({
type: "GET",
url: "http://www.somesite.com/GetLocation",
dataType: "jsonp",
contentType: "application/json;charset=utf-8"
}).done(function (msg) {
loc = msg.IAmAt;
});
return loc;
}
when called, from elsewhere to pass data along to the next page/event, the result is just empty.
What is the best way for it to return the data only when the ajax call is finished? User experience is not important here but what is important is that it gets the data fully before returning from the function.