0
我想添加一個條目到使用javascript的xml文件。下面的代碼應該添加一個名爲book的節點到這個文件中。但它根本不起作用。我也嘗試了一些其他代碼來改變xml數據庫中的條目,但也沒有成功。那麼我的過錯是什麼?在javascript中添加節點到xml文件
CODE:
function loadXMLDoc(dname) {
if (window.XMLHttpRequest) {
xhttp=new XMLHttpRequest();
}
else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
xmlDoc=loadXMLDoc("database.xml");
newNode = xmlDoc.createElement("entry");
newNode.nodeValue = "aaaaa";
x=xmlDoc.documentElement;
x.appendChild(newNode);
XML文件(database.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<database>
<entry>
<title>Everyday Italian</title>
<content>Strange. I seem to get hungry about the same time every day!</content>
<time>August 7, 2012, 6:24 PM</time>
<comment>Giada De Laurentiis</comment>
</entry>
<entry>
<title>I'm Hungry</title>
<content>I really need something to eat!!</content>
<time>August 7, 2012, 6:24 PM</time>
<comment>Giada De Laurentiis</comment>
</entry>
</database>
你能舉一個例子來說明如何實現這個POST OR PUT方法嗎? –
這完全取決於您將哪個軟件用作Web服務器。你在使用IIS嗎?或Apache?或NodeJS? –
修復了整個事情與PHP。多麼愚蠢的想法來修改文件客戶端;) –