2
Hello, guys, I have a problem: I’m trying to create a node in an xml with jquery and I can’t... I have an xml file which I get it with ajax:
<?xml version="1.0" encoding="UTF-8"?>
<dados>
<usuarios>
<usuario>
<login>usuario</login>
<senha>senha123</senha>
</usuario>
</usuarios>
</dados>
I can read user nodes easily. But I’m not able to add another user. Can anyone help me? If there is any form with pure javascript there is also no problem. Thanks already!
Edit 1: The jquery code I’m using is this:
$.ajax({
url: "../xml/dados.xml",
type: "get",
dataType: "xml",
success: function(data) {
xml = data;
var xmlDoc = $(xml);
var element = xmlDoc.filter('usuarios');
$(element).attr('type', 'vip');
$(element).append("<usuario><login>usuario2</login><senha>senha321</senha></usuario>");
$("body").append(xmlDoc);
}
});
I found this looking code on this jquery forum: https://forum.jquery.com/topic/adding-xml-nodes-to-an-xmldocument-with-jquery-1-5
You could post the javascript code you are using to try to add user?
– Luiz Lanza
I will edit the post
– Krint