如何从客户端修改存储在服务器上的 .JSON 文件? [英] How can I modify a .JSON file stored on server from client side?

查看:217
本文介绍了如何从客户端修改存储在服务器上的 .JSON 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个当前在服务器上运行的 web 应用程序,其中还有一些 .JSON 文件,我希望用户能够输入一些信息并按 Enter 键,这些信息将被存储到.JSON 文件.

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 应用程序是用 HTML、CSS 和 vanilla Javascript 编写的,没有使用任何外部库.

The webapp is written in HTML, CSS, and vanilla Javascript, there aren't any external libraries being used.

我已经使用 GET 函数从要在应用程序中使用的 .JSON 文件中提取信息,而且我知道我不能直接使用 javascript 修改服务器端文件,除非我正在运行 Node.js 服务器(它目前不是一个选项).

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).

所以我相信我唯一的选择是使用服务器端语言,例如 PHP(我对此一无所知)来修改文件.我的问题是,我怎样才能相对简单地做到这一点?可能是在运行 JS 函数以将更改推送到文件时.

So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file. My question is, how can I do this relatively simply? Possibly when a JS function is run to push the change to the file.

谁能给我一小段示例代码,或者向我指出一些简单的文档或如何做到这一点的教程,我根本不擅长服务器端编程,因为这是一个简单的只是为我设计的项目,我目前不想深入研究 PHP.

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(我对此一无所知)来修改文件.

So I believe my only option is to use a server side language such as PHP (which I nothing about), to modify the file.

既然您已经了解 JavaScript,那么我将重新审视为什么您觉得不能使用 Node.js 服务器端.无论如何,如果您继续使用 PHP...

Since you already know JavaScript, I'd revisit why you feel you can't use Node.js server-side. In any case, if you're going ahead with PHP...

要写入文件,file_put_contents().

To write files, file_put_contents().

要编码 JSON,json_encode().

To encode JSON, json_encode().

请注意,那里还有其他服务器.您不必用 PHP 编写自己的东西.如果您不需要检查发送的内容,您甚至可以修改您的网页服务器的配置以接受 PUT.

Note that there are other servers out there. You don't have to write your own stuff in 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.

这篇关于如何从客户端修改存储在服务器上的 .JSON 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆