This is driving me nuts. I can't work it out stepping through with Firebug either. Can someone please explain what is going on here?
Basically I have an incoming text file where each line contains a pipe-delimited record. I'm splitting these into an array of array of string for later use in an autocomplete textbox. The code is as follows:
<script type="text/javascript">
$(function () {
var rawData = new Array();
$.get("/sample.txt",
function (data) {
var raw = data.split('\n');
for (var i = 0; i < raw.length; i++) {
rawData.push(raw[i].split('|'));
};
alert(rawData); // 1st sanity check
}
);
alert(rawData); // 2nd sanity check
alert(rawData); // 3rd sanity check
For some reason the first sanity check works fine - it displays all the data as I'd expect. The second one displays that rawData is empty... but the 3rd one shows all of the data again. Removing the 1st sanity check doesn't affect the 2nd and 3rd.
How is this possible? Why is this so? This is driving me crazy.