I have the following jQuery code in my HTML page:
$.post("MyPHP.php", {category: CATEGORY}, function(data){var test = data;});
But I can't seem to use test anywhere else in my page. I know this is AJAX so I have to wait for $.post to complete but the variable test is never set. If I instead use the return data to change the innerhtml of a paragraph, the paragraph updates after a small delay.
Any thoughts?
EDIT: Cracked it! You can call another function from the $.post return function, ie: function(data){setVar(data)}); and simply define the setVar(data) function as follows:
function setVar(data){test = data;}
Provided test has already been defined in global scope var test; you can use it through out the rest of your code.