Read/Write Server side files ~ Comment Board (JQuery)

元气小坏坏 提交于 2020-01-03 05:01:10

问题


I am searching for the best and easiest way to have the client side be able to "post" text to a server side file (.txt) and then save it to the text file. I would like to set up a simple board to post comments. Something quick and easy?

I've looked around and it seems there are many ways out there. I haven't found something that simply allows read/write, while only utilizing JQuery functionality. Advice?


回答1:


jQuery is a framework built on top of javascript. Javascript is a language thet runs within the browser. We call the browser the 'client'. That's why we call javascript a form of client side scripting.

to read/write files on the server, you'll need to use a server side language such as PHP.

If you do so, you can either set the action attribute of a form, or the href method of a link to the php scrip, or request it using AJAX, which is really easy to do.

If you want your site to be any good when you get some visitors, I think you should use a database for comments instead of a .txt files. However, for something that doesn't change that much, such as blog posts, you can use static HTML or txt files, these are quicker to serve then database contents.




回答2:


jQuery is a client side language, which means you can not execute code on the server with it. What you could do, is post to a server side script with AJAX jQuery, which is pretty easy, but requires you to have a little knowledge of a server side programming language to write to the file.

Use this code to post to the server:

$.post("/url/to/server.php", {text: $("#text").val()});


来源:https://stackoverflow.com/questions/6021877/read-write-server-side-files-comment-board-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!