0

I got a very simple txt file in JSON format:

{
  "menu": "File1",
  "bday": [
      {
          "name": "teo",
          "date":"22"
      },
      {
          "name": "john",
          "date": "9"
      },
      {
          "name": "maria",
          "date": "15"
      }
   ]
}

All I want is to just fetch the data and print them. Like:

teo : 22
john:9

...etc...

I don't care about this. I just want to fetch the data.

2 Answers 2

3

Your answer is plainly XMLHttpRequest, which is multi-browser compatible JavaScript without need for a library. You can always create your own library for some backward-compatibility.

Sign up to request clarification or add additional context in comments.

1 Comment

AJAX, as we know it, without all the bells and whistles that come with libraries.
2

Put the JSON in a file on your server (for example, data.js) and then use jQuery to fetch the file. Something like this:

var json;
$.getJSON("data.js", function(data){
    json = data;
});

2 Comments

thnx rcravens but i dont want jQuery or any other lib. is this possible or must be on a server ?
Javascript has no native filesystem type routines. Your only options to load it into JS is to embed it into the same file that the JS is loaded from, or have it served up via AJAX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.