Hello, I'm trying to call a function that contains jQuery code. I want this function to return the results of the jQuery statement. It is not working and I'm trying to figure out why.
function showGetResult (name) {
var scriptURL = "somefile.php?name=" + name;
return $.get(scriptURL, {}, function(data) { return data; });
}
alert (showGetResult("John"));
The alert displays "[object XMLHttpRequest]
." However, if I run the jQuery statement by itself, outside of a function, it works fine -> $.get(scriptURL, {}, function(data) { alert(data); })
I'd like to be able to re-use this code by putting it inside of a function that returns the $.get data. What fundamental mistake am I making here?