是否可以在没有服务器端语言的情况下将信息写入JSON文件?

时间:2016-01-11 22:34:49

标签: javascript jquery json ajax

我之前已经看过这个问题并且答案通常以应该使用服务器端语言完成....因为我不知道服务器端语言但是我想知道这是否是可以用我的直接知识。

我有一个JSON文件,通过jquery使用AJAX是否可以在不使用服务器端语言的情况下将数据写入JSON文件?我可以在纯粹的javascript和jquery中完成这个吗?我的想法是在我的html中输入一个表单来将数据推送到JSON文件。

编辑:我正在构建的解决方案是用于内部网使用,所以它不会暴露在我公司以外的任何地方,我只是想建立一个比excel电子表格更好的工具来存储数据。我想将数据存储在本地托管Web服务器(如XAMP或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."
 }]

1 个答案:

答案 0 :(得分:1)

是的,您可以配置Apache和Nginx等网络服务器软件,以允许来自公共IP的PUT / POST请求actually store files on the server's file system

但如果没有很好地锁定,这是一个非常糟糕的主意,会使您的服务器暴露于荒谬的黑客攻击和DoS风险,并且可能会在几天内爆炸。此外,配置和学习使用的工作要比学习获得相同结果的单行PHP更多:

file_put_contents('myserverfile.txt', file_get_contents('php://stdin'));