I have something like this, where it is a simple call to a script that gives me back a value, a string..
function testAjax() {
$.ajax({
url: "getvalue.php",
success: function(data) {
return data;
}
});
}
but if I call something like this
var output = testAjax(svar); // output will be undefined...
so how can I return the value?
the below code does not seem to work either…
function testAjax() {
$.ajax({
url: "getvalue.php",
success: function(data) {
}
});
return data;
}
The only way to return the data from the function would be to make a synchronous call instead of an asynchronous call, but that would freeze up the browser while it’s waiting for the response.
You can pass in a callback function that handles the result:
Call it like this: