好的,我知道了!所以我们在这里为任何感兴趣的人:
Asp.net 服务器(保存.aspx 文件):
string txtString = Request["txtString"];
Response.Clear();
Response.AppendHeader(
"Content-Disposition",
"attachment;
filename=myFile.txt"
);
Response.ContentType = "application/x-download";
Response.Write(txtString);
Response.End();
并感谢这篇文章!:
JavaScript 发布请求,如表单提交
Javascript:
function saveTxt() {
var myString = getTxtString();
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "save.aspx");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "jsonString");
hiddenField.setAttribute("value", myString);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
}