Jquery Ajax将数据发布到本地文件

我试图将本地文本文件的内容读入文本区域,然后修改textarea,然后将修改后的文本区域值保存到同一本地文件中。 我不能使用服务器端代码,所以尝试使用Jquery Ajax post方法。 我的HTML看起来像这样 –


  Edit Properties    var testpath; var buildpath; var dataOnFile; var buildnum; function loadFile() { var URL = "somepath"; if (window.XMLHttpRequest) { xhttp = new XMLHttpRequest(); } else { xhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET", URL, false); xhttp.send(""); return xhttp.response; } function edit(){ $(document).ready(function() { //console.log(loadFile()); $("#area").val(loadFile());//load the contents correctly $("#save").click(function() { testpath = window.location; buildpath=(testpath+"").replace("somepath1",""); buildpath= buildpath + "somepath2"; dataOnFile=$("#area").val(); console.log(dataOnFile);//logs updated value of text area $.ajax({ type : "POST", async:false, data : dataOnFile, url:buildpath, dataType : "text", success: function(data) { alert("File Saved"); } }); }); }); }   


这可以正常工作,但我的更改不会保存到文件中。 任何解决此问题的指针?

Javascript的设计方式拒绝访问文件系统。 如果你想mannupilate文件,你应该使用像PHP这样的服务器端语言。 本教程可能会帮助您了解您的尝试:

初学者使用PHP指导Ajax