0

I really want to use this code to import json file to javascript

var treeData;
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "test.json", true);
oReq.send();
function reqListener(e) {
    treeData = JSON.parse(this.responseText);
}

But i can't use JSON.parse for some reason

Someone told me I have to import Mongoose web server too set my local folder in javascript

please teach me how to import it thanks

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
user3248233
  • 221
  • 1
  • 2
  • 5
  • Your question is a bit confusing but JSON.parse is part of ECMAscript 5 and most browsers support it natively. @see http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript – mccainz Jan 30 '14 at 14:03
  • http://stackoverflow.com/questions/21450227/import-json-file-to-javascript soneone advice me to import it – user3248233 Jan 30 '14 at 14:05
  • Mongoose http://mongoosejs.com/ or mongoose https://code.google.com/p/mongoose/? – SteveLacy Jan 30 '14 at 21:42
  • Why is your `treeData` a global variable - the value is only available inside `reqListener`? – Bergi Jan 30 '14 at 22:11
  • @user3248233: That's completely unrelated from `JSON.parse`. He's telling you that `XMLHttpRequest` cannot load files from your disk for security reasons. – Bergi Jan 30 '14 at 22:14

1 Answers1

0

If you can import jquery, you can do $.parseJSON(this.responseText);

vishakvkt
  • 864
  • 6
  • 7