How to change the value of an xml node with jquery?

前端 未结 1 1173
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 05:14

This may be a simple question though can´t figure out how to do it. I want to load and modify an xml file, then save the xml through php.

Here is the code:



        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-15 05:38

    Is this what you are looking for?

    $(this) is each of the menu_items you iterate over with .each()

    Your code becomes

    $(xml).find('menu_item').each(function(){
       $(this).text("New Value");
    });
    

    Hope this helps

    EDIT

    To post this back to the server I would do this:

    $.post('save_xml.php', { xml: $(xml)}, function(data){alert("Data Loaded: " + data);});
    

    and then in the PHP file

     
    

    This code is untested, and there could be any number of reasons it doesn't work, write permissions on the files etc.

    0 讨论(0)
提交回复
热议问题