Hi,
When trying out jquery, I ran into seemingly very simple problem. I
did a search on internet and did not get any satisfactory result. I am
suspecting that the mistake is very simple, so anyone more experienced
can help me.
What I am trying to do is load data from server, then present it in
the table, and plot it later. Since I am intending to use flot plugin,
and it accepts arrays as an argument, I thought that I load the file,
save it to some array, and then plot it when time comes (when user
presses something, etc.) So my javascript code goes like this:
<script type="text/javascript" src="js/jquery-1.3.2.js"></
script>
<script type="text/
javascript">
var tb1=[];
$(document).ready(function() {
$.post("data/echocsv.php", function(text) {
tb1=text.split("\n");
})
alert(tb1);
});
</script>
echocsv.php is very simple, it just grabs csv file (text file) and
returns it:
<?
$ff=file_get_contents("data.csv");
echo $ff;
?>
Yet when I run this script, nothing happens. If I move the alert into
callback function, then everything is alright. I understand that it is
possible that ajax query is not performed before the alert. But I did
not find out how to know when the query is succesfull. From examples
in the web I saw, that .ajax call is more frequently used, maybe I
should use it also?
Thanks for any help,
Vaidotas