I have a function that is not returning a value the way I would like it to. What the function does is get information that is echoed from a PHP page (the PHP page has an SQL query) and return it. Here it the code:
function getValues(var1,var2) {
$.post("http://url/to/file.php", {var1:var1,var2:var2}, function(data) {
values = data.split(',');
return values[0];
});
}
I know that the PHP file is working because if I were to write alert(data); or alert(values); I can see the values there. When I call the function, for example, var result = getValues(5,6); result is undefined. Maybe it is because they are not in a list or an array? Help appreciated, thanks.
$.postsuccess is executed long aftergetValuesreturns. The structure used here simply won't work in an asynchronous nature.valuesto be a global variable?