Is it possible to add, remove xml nodes using jquery $ .ajax?

I want to remove some parts or add some nodes in xml using the jquery, I try it with append, empty, removebut they do not seem to work ( in .ajax $ ):

success:function(xml){
    $(xml).find("layout").append('<app id="' + $children.eq(i).attr("id") + '"></app>');
    $(xml).find("layout").empty();
}

Also I find that there is no google tutorial. So I'm wondering, is it possible to add or remove nodes in xml using jquery?

Ok, I write it in detail , the xml file just saves in the local domain as Database / UserConfig / config.xml here is my Ajax code :

function layout_change()
{
    var $children=$input.children();

    $.ajax({
        type: "get",
        url: "Database/UserConfig/config.xml",
        dataType: "xml",
        timeout: 2000,
        beforesend:function(xml){
            $(xml).find("layout").empty();
        },
        success:function(xml){
            for(var i=0;i<$children.length;i++)
            {
                $(xml).find("layout").append('<app id="' + $children.eq(i).attr("id") + '"></app>');              
            }
        },
        error:function(){}
    });
}

or can it be done using javascript? or can only be done with the server language, for example C #? ......

here is my demo xml:

<layout>
        <app id="id-4"></app>
        <app id="id-5"></app>
        <app id="id-6"></app>
        <app id="id-1"></app>
        <app id="id-2"></app>
        <app id="id-3"></app>   
</layout>
+3
1

jQuery - XML javascript. jQuery API- ajax , , , ajax-, dataType xml ( - ). jQuery $.ajax() dataType:

"xml": XML-, jQuery.

XML , , jQuery. , CSS XPath XML- .

empty remove , , append: jQuery, - ( ), XML ( HTML). , node DOM jQuery, append:

//Either of these will work
var elem = document.createElement('app');
xml.find('layout').append(elem); // Appends <app></app> to <layout>
xml.find('layout').append($('<app>')); // Does the same

// You can also you use other manipulation functions such as `attr`
xml.find('layout').append($('<app>').attr('id', 'ego'));

, , , . $.ajax beforeSend, , XMLHttpRequest , XML, . empty , .

, Database/UserConfig/config.xml beforeSend, , , , beforeSend , ajax . , xml, , , , jQuery XMLHttpRequest, .

+8

Source: https://habr.com/ru/post/1776600/


All Articles