最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Load JSON data without AJAX - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Sep 28, 2013 at 21:33 Alexander GladyshAlexander Gladysh 41.5k33 gold badges110 silver badges164 bronze badges 10
  • 1 You could simply include the data in your Javascript file. – Lars Kotthoff Commented Sep 28, 2013 at 21:36
  • 1 @Lars, it could be 10 mb size – davidkonrad 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. – Tetsujin no Oni 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. – davidkonrad 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. – Tetsujin no Oni Commented Sep 28, 2013 at 21:56
 |  Show 5 more ments

1 Answer 1

Reset to default 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 plicated as using XMLHttpRequest, and risks browsers deciding that JSON should be downloaded instead of rendered.

Use XMLHttpRequest. It isn't plicated.

发布评论

评论列表(0)

  1. 暂无评论