Reputation: 3
I have a js function that was supposed to insert data into a XML file. Everything is running in a local server. The function arguments are variables sent from another function.
function xmlinsert(srcf, typef, textf) {
console.log("Type: "+typef);
console.log("Source: "+srcf);
console.log("Text: "+textf);
//XML Connection
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","./include/xml/gallery.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var divi = xmlDoc.createElement("divi");
var photo = xmlDoc.createElement("photo");
var source = xmlDoc.createElement("source");
source.appendChild(xmlDoc.createTextNode(srcf));
var type = xmlDoc.createElement("type");
type.appendChild(xmlDoc.createTextNode(typef));
var text = xmlDoc.createElement("text");
text.appendChild(xmlDoc.createTextNode(textf));
var picname = xmlDoc.createElement("picnamet");
picname.appendChild(xmlDoc.createTextNode("A"));
photo.appendChild(source);
photo.appendChild(type);
photo.appendChild(text);
photo.appendChild(picname);
divi.appendChild(photo);
ix=xmlDoc.getElementsByTagName("root")[0];
ix.appendChild(divi);
}
The thing is, nothing happens when the function is executed. The file remains the same. The same file is used by another function that actually reads and displays its data. This functions correctly. No errors are shown in the browser's console.
What it wrong in the code? How come I'm able to read data, but not write? Is it because of some permission issue?
Thanks in advance!
Upvotes: 0
Views: 70