0

i have seen questions posted on this before and the answer usually ends in that it should be done using a server side language.... seeing as i dont know a server side language as of yet i wanted to know if this is possible with my immediate knowledge.

i have a JSON file, using AJAX through jquery is it physically possible to write data to a JSON file without the use of a server side language? can i accomplish this in pure javascript and or jquery alone? My thought is to have a form input in my html to push data to the JSON file.

edit: The solution i am building is for intranet use so it wouldnt be exposed anywhere outside of my company, im just looking to build myself a better tool than an excel spreadsheet for storing data. I would like to store the data on the client side of a local hosted web server like XAMP or WAMP.

[{
    "number":1,
    "name":"Keith Moore",
    "link":"http://www.moorelife.org/freedownloads-serieslist.php?",
    "image":"keith_moore.jpg",
    "details":"Teacher/Pastor, I refer to Keith as my \"bible college experience,\" he has 30+ years of free audio and video available on any and every subject."
  },
  {
    "number":2,
    "name":"Kenneth Hagin",
    "link":"https://www.youtube.com/playlist?list=PLIXcY2izjpDgROo3MRlAU2MJSyjthXLLc",
    "image":"kenneth_hagin.jpg",
    "details":"Prophet, with nearly 70 years of ministry under his belt, Hagin most commonly preached on the subject of faith in Gods word."
  },
  {
    "number":3,
    "name":"Bill Johnson",
    "link":"https://www.youtube.com/playlist?list=PLEtP4XPKdli585uNfIU8WNRYawCusmEYK",
    "image":"bill_johnson.jpg",
    "details":"Apostle/Pastor, Bill pastors a church in Redding California named Bethel Church, the church is most known for miracles, signs and wonders."
  },
  {
    "number":4,
    "name":"Todd White",
    "link":"https://www.youtube.com/user/ToddWhiteChannel/videos",
    "image":"todd_white.jpg",
    "details":"Evangelist, Todd takes love on the streets and preaches the gospel with radical miracles taking place everywhere he goes."
 }]
alilland
  • 2,039
  • 1
  • 21
  • 42
  • You want to write the file onto a server without any server side code? – Jaromanda X Jan 11 '16 at 22:37
  • 1
    Where are you hoping to store your file? – Lee Taylor Jan 11 '16 at 22:37
  • 1
    sure it is. depends on where you want to store the file, though. – user428517 Jan 11 '16 at 22:43
  • Let me see if I understand. You have a JSON file or object that have obtained via an AJAX request. If this is the case then the file/object is residing on the client side of things. If you needed to, you could write the object the the header stream and have JS give you a download see this post http://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser if your looking to save it to the server, then you'll need to implement something server side – Lionel Morrison Jan 11 '16 at 22:52

1 Answers1

1

Yes, you can configure webserver software like Apache and Nginx to allow PUT/POST requests from public IPs to actually store files on the server's file system.

But that's an extremely bad idea if not well locked down, will expose your server to ridiculous hacking and DoS risks, and likely blow up in your face within days. Also, it's more work to configure and learn to use than just learn the single line of PHP that achieves the same result:

file_put_contents('myserverfile.txt', file_get_contents('php://stdin'));
Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136