Read/Write Server side files ~ Comment Board (JQuery)
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 a开发者_如何学Pythonre many ways out there. I haven't found something that simply allows read/write, while only utilizing JQuery functionality. Advice?
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.
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()});
精彩评论