简体   繁体   中英

Possible to use JQUERY + JSON to retrieve data without PHP GET/POST?

Instead of POST-ing to a server PHP file to retrieve JSON structured data. Is it possible to script a cron job to spit out JSON structured data to a plain text file, serve it behind nginx, and then have JQuery read from that static plain text file to fill the client's browser?

Sure, I don't see why not.

Just point your $.json() request to that file and make nginx respond with the proper content type.

Obviously, you won't be able to specify any parameters. (Well you are, but they won't do anything.)

Also be aware that the static json resource's caching settings may differ from those for a PHP script.

Sure you can, just use $.getJSON() here, like this:

$.getJSON("/path/to/file.json", function(data) {
  //use data
});

Inside that callback data will be your JSON data, whatever that is: an object, Array, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM