Load XML file from server and List XML data - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:load

Description

Load XML file from server and List XML data

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("div").load("yourfile.xml",function(response, status){
            if (status == "success"){
                $("div").html("<ol></ol>");
                $(response).find("itemInXML").each(function(){
                    var item_text = $(this).text();
                    $('<li></li>').html(item_text).appendTo('ol');
                });//ww  w  .j  av  a 2 s . c  o  m
                console.log("Count:" + $(response).find("cd").length)
            }
        });
    });
});
</script>
</head>
<body>

<div></div>
<button>test</button>

</body>
</html>

Related Tutorials