Here's what I wanted to do. 1. Load a text file (server side) say testJSON.txt [DONE] 2. Load the content from text file [DONE] 3. Dump the loaded data into an array for JavaScript [??HOW??]
Code snippet :
var data2, externalData;
$.get("testJSON.txt",function(externalData){
// Pop an alert showing the typeof the object taken from text file [WORKS]
alert("Data from JavaScript file: " + externalData + "typeof object " + typeof externalData);
// Convert the string from text file into JavaScript array [WORKS]
data2 = eval('['+ externalData + ']');
});
// **DOESN'T WORK**
alert(data2);