I’m experimenting with MCV using jquery. I’m making a call to an api, which returns data – what I want to do is return the data to a variable rather than call an additioanl function within my model. The following code doesn’t do what I wish though (the_data = result). Any ideas how I can achieve this?
function lookForSomething()
{
var the_data = $.ajax({ type: "GET",
url: TheUrl,
dataType: "jsonp",
success: function(result) { return result; }
});
return the_data;
}
Many thanks,
J
If understand you correctly, you want the data returned by TheUrl to be the return value of the lookForSomething.
Technically, you could do this, with the async option:
I strongly urge you not to do this. It’s un-Javascript-like and it will lock up the user’s browser while it’s running. Much better to pass in a callback to the function and invoke it from
success.