the duplicate question referred tells us how to use ajax/post calls. my question is how to use the data returned by the anonymous function.
i am using the jquery POST method to get some data from mysql. the call is:
$.post("/php/practice.php",{cat:catname}, function(xdata) {
qdata=JSON.parse(xdata);
});
this is working fine and i get my required array, qdata.
so, i can access qdata if i do the following:
$.post("/php/practice.php",{cat:catname}, function(xdata) {
qdata=JSON.parse(xdata);
alert(qdata[0][0]);
});
qdata is a 2-D array with 140 rows and the values are all there
but if i try to use qdata outside this post, qdata comes up as 'undefined'. eg
$.post("/php/practice.php",{cat:catname}, function(xdata) {
qdata=JSON.parse(xdata);
});
alert(qdata[0][0]);
if i place the alert outside the post call i get nothing.
how do i get around this problem?