Sunday, 15 June 2014

javascript - Load an array from an external txt -


If I store an array using a txt file, how can I get it back to jQuery?

  ['parrot', 'green'], ['crow', 'black'], ['duck', 'white']   

How do I do it

  var myrr = [['parrot', 'green'], ['crow', 'black'], ['duck'] I can load as 'White'] ];  

This is what I am trying to do not work.

  var myArr; $ .ajax ({url: 'files / external.txt'}) done (function (d) {myArr = JSON.parse ('[+ + + d +'] ');});  

JSON is trying to parse 'external', but Content does not follow JSON-specifications

See wrapping all the text in double quotes instead of single-quotation

  //external.json [["parrot", "green"], ["crow "," Black "], [" Duck "," White "]]  

your code can then be viewed

  $ Ajax ({url: 'files / external.json'}) done (function (d) {myArr = JSON .PERS (D);});  

No comments:

Post a Comment