Reputation: 607
I have in a file (.txt) something like this:
A[1]=[722680,1,86,121,'Sevilla','Granada CF'....]
A[2]=[807806,29,16516,2007,'Centro Sportivo Paraibano'...]
(A string formatted as a array)
I want to load those lines(with jquery) and manipulate it like any other arrays.
EX:
if(A[i][16]!="0") G_yellow = "<img src='images/yellow" + A[i][16] + ".gif' alt='' />";
I need a idea of script to do that.
THanks!
Upvotes: 1
Views: 65
Reputation: 4798
Use eval to execute the JavaScript in the file:
eval(str);//where str is the file
Now you have access to the variables defined in the file, and can manipulate the arrays.
If you need the code to retrieve the file, you can look into using jQuery's get method http://api.jquery.com/jQuery.get/
$.get('test.txt', function(data) {
eval(data);
});
Note: Evaluating raw JavaScript on a production server, and not having control over the file is a definite security risk
Upvotes: 2