9

In my small JS web-application, I use some JSON data.

The data is on server in a separate static .json file.

My application, being small, does not use any frameworks, not even jQuery. And I do not want to mess with XMLHTTPRequest myself.

Is there a way to load my JSON data without AJAX? (And without renaming the file to .js and imitating JSONP or including the data in existing JS sources.)

It is OK if it will work only in modern browsers.

10
  • 1
    You could simply include the data in your Javascript file. Commented Sep 28, 2013 at 21:36
  • 1
    @Lars, it could be 10 mb size Commented Sep 28, 2013 at 21:37
  • 1
    It seems less than sensible to declare a web application 'too small to use jQuery' when it will be processing a potentially 10mb JSON object. Commented Sep 28, 2013 at 21:40
  • 1
    @Tetsujin, Yes - but there is really good reason in trying anything to avoid the inclusion of a 9789 lines library (not minified), if the same thing easily can be done in pure javascript. Commented Sep 28, 2013 at 21:53
  • 2
    @davidkonrad: I am both with you on that, and at the same time consider jquery-current to be the equivalent of MSVCRT(current).dll as a dependency. Certainly not worried about 9kloc unminified when we're talking about js that's a 304 on a well-configured reference. Commented Sep 28, 2013 at 21:56

1 Answer 1

7

There aren't any sensible ways.

You might be able to display it in an iframe and read it from there, but (since you will have to deal with timing issues) that is at least as complicated as using XMLHttpRequest, and risks browsers deciding that JSON should be downloaded instead of rendered.

Use XMLHttpRequest. It isn't complicated.

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

1 Comment

While using XMLHTTPRequest is not complicated, it requires me to switch from file:// to an actual HTTP server for my development workflow. Which is a little more cumbersome. But, thanks to python -mSimpleHTTPServer, not too much.

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.