jQuery load() load xml

Introduction

Load xml from ajax

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/* w w w  .  j  av a2 s  .c o  m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("div").load("demo_cd_catalog.xml",function(response, status){
      if (status == "success"){
        $("div").html("<ol></ol>");
        $(response).find("data").each(function(){
          let item_text = $(this).text();
          $('<li></li>').html(item_text).appendTo('ol');
        });
        document.getElementById("demo").innerHTML = 
                "There are " + $(response).find("value").length;
      }
    });
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<div></div>
<button>Get</button>

</body>
</html>



PreviousNext

Related