使用javascript和node.js如何通过ajax将内容发布到文本文件

使用javascript和node.js如何通过ajax将内容发布到文本文件,javascript,ajax,node.js,Javascript,Ajax,Node.js,使用javascript和node.js如何通过ajax将内容发布到文本文件 <html> <body> <input type="button" value="Click Me" onclick="postContent()"> <script> function postContent(){ var req=new XMLHttpRequest(); req.open('post','add

使用javascript和node.js如何通过ajax将内容发布到文本文件

<html>
<body>
     <input type="button" value="Click Me" onclick="postContent()">
  <script>
    function postContent(){
        var req=new XMLHttpRequest();
        req.open('post','addContent.js',true);//in this sample.txt file i want to insert some content
        req.send();
      }

  </script>
 </body>
</html>

您可以使用服务器端脚本将内容写入文本文件,并使用Ajax调用该服务器端脚本

req.open('POST', 'FilePoster', true);
req.send(dataToWrite);
为新问题编辑:

req.open('post','addContent.js',true);
addContent.js应该是在主机和端口上运行的HTTP服务器

如果addContent.js是一个运行在本地主机和端口8080上的节点HTTP服务器,则打开调用应为

req.open('POST', 'localhost:8080', true);

好的,在服务器端脚本中,我必须编写代码将内容写入文本文件。
req.open('POST', 'localhost:8080', true);