如何使用 javascript 在客户端保存 xml 文件...?
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", "User.xml", false);
xhttp.send("");
xmlDoc = xhttp.responseXML;
xmlDoc.getElementsByTagName("Username")[0].childNodes[0].nodeValue = 'asdasf';
xmlDoc.getElementsByTagName("password")[0].childNodes[0].nodeValue = 'asdAS';
xmlDoc.getElementsByTagName("UserId")[0].childNodes[0].nodeValue = '12';
xmlDoc.save("User.xml");
这不起作用..显示错误,因为保存不是函数。
谢谢 苏妮莎。
最佳答案
这在 JavaScript 中是不允许的。这将是一个安全漏洞。
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files. Second, scripts are constrained by the same origin policy: scripts from one web site do not have access to information such as usernames, passwords, or cookies sent to another site. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox.
关于javascript - 使用 javascript 创建和修改 xml 文件(想在客户端保存 xml 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1795615/