简体   繁体   English

如何从客户端修改存储在服务器上的 a.JSON 文件?

[英]How can I modify a .JSON file stored on server from client side?

I'm working on a webapp that is currently running on a server, where there are also some.JSON files, which I would like the user to be able to type some information and press enter where it will be stored to the.JSON file.我正在开发一个当前在服务器上运行的 web 应用程序,其中还有一些 .JSON 文件,我希望用户能够输入一些信息并按 Enter 键将其存储到 .JSON 文件中.

The webapp is written in HTML, CSS, and vanilla Javascript, there aren't any external libraries being used. webapp 是用 HTML、CSS 和 vanilla Javascript 编写的,没有使用任何外部库。

I am already pulling information from the.JSON files to be used in the app using the GET function, and I know I can't directly modify server side files with javascript unless I'm running a Node.js server (which isn't currently an option). I am already pulling information from the.JSON files to be used in the app using the GET function, and I know I can't directly modify server side files with javascript unless I'm running a Node.js server (which isn't currently an选项)。

So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file.所以我相信我唯一的选择是使用服务器端语言,如 PHP(我对此一无所知)来修改文件。 My question is, how can I do this relatively simply?我的问题是,我怎样才能相对简单地做到这一点? Possibly when a JS function is run to push the change to the file.可能在运行 JS function 以将更改推送到文件时。

Can anyone give me a sliver of example code, or point me in the direction of some simple documentation or tutorial on how to do this, I'm not very adept at server side programming at all, and as this is a simple project just for me, I don't want to dive deep into PHP at the moment.谁能给我一些示例代码,或者指出一些简单的文档或教程的方向,我根本不擅长服务器端编程,因为这是一个简单的项目我,我现在不想深入研究 PHP。

Thank you in advanced!提前谢谢你!

So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file.所以我相信我唯一的选择是使用服务器端语言,如 PHP(我对此一无所知)来修改文件。

Since you already know JavaScript, I'd revisit why you feel you can't use Node.js server-side.既然你已经知道 JavaScript,我会重新审视为什么你觉得你不能使用 Node.js 服务器端。 In any case, if you're going ahead with PHP...无论如何,如果您要继续使用 PHP ......

To write files, file_put_contents() .要写入文件, file_put_contents()

To encode JSON, json_encode() .编码 JSON, json_encode()

Note that there are other servers out there.请注意,那里还有其他服务器。 You don't have to write your own stuff in PHP.您不必在 PHP 中编写自己的东西。 If you don't need any checking on what's being sent, you can probably even modify your web server's config to accept a PUT .如果您不需要对发送的内容进行任何检查,您甚至可以修改 web 服务器的配置以接受 PUT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从客户端调用服务器端按钮单击功能? - How can i call a server side button click function from client side? 如何从服务器端向客户端发送变量? - How can I send a variable from the Server-side to the Client-side? 如何在客户端修改js文件? - How to modify js file on client side? 大JSON文件-如何在服务器中压缩和在客户端解压缩? - Big JSON file - how to compress in the server and decompress in the client side? 如何将json对象从jsp页面的jsp部分传递到javascript部分,即从服务器端到客户端? - How to pass a json object from the jsp part of a jsp page to the javascript part i.e from server side to client side? 如何从服务器(Node JS和Express)的客户端上接收和使用JSON对象? - How do I receive and use a JSON object on the client-side from the server (Node JS and Express)? 如何将/ post JSON数组从客户端传递到服务器? - How to pass /post JSON array to the server from the client side? 客户端如何知道文件是从服务器下载或接收的? - How can client-side know that file is downloaded or received from server? 如何从客户端获取 firebase 存储 json 文件 - how to fetch firebase storage json file from client side 通过从客户端代码调用服务器端代码来修改UpdatePanel - Modify an UpdatePanel by calling server-side code from client code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM