if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","t1.txt",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseText;
xmlhttp.open("w","t1.txt");
xmlhttp.writeln('hai');
xmlhttp.close();
console.log(xmlDoc);
我将使用读取t1.txt文件XMLHttpRequest()
,如何在t1.txt的同一文件中写入更多文本
你不能 在不禁用许多安全性选项的情况下,不允许浏览器端javascript写入客户端计算机。
相反,您可以使用以下代码下载新文件
function downloadContent(name, content) {
var atag = document.createElement("a");
var file = new Blob([content], {type: 'text/plain'});
atag.href = URL.createObjectURL(file);
atag.download = name;
atag.click();
}
downloadContent("t1.txt","hello world");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句