我认为一个帖子会是更好的方式来做到这一点。处理转义数据比内存文件和使用客户端 javascript 将文件推送到服务器更容易、更成熟。此外,转义数据是有原因的。您正在尝试做的是迎接许多安全漏洞。
尝试做这样的事情。摘自将 javascript 输出写入服务器上的文件的片段
var data = "...";// this is your data that you want to pass to the server (could be json)
//next you would initiate a XMLHTTPRequest as following (could be more advanced):
var url = "get_data.php";//your url to the server side file that will receive the data.
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);//check if the data was revived successfully.
}
}
http.send(data);