Friday, November 7, 2014

Read xml in juqery asp.net

 
 In this example we have shown how to read the xml in jqeury. I have created the sample employee.xml
 
<?xml version="1.0" encoding="utf-8" ?>
<EmployeeList>
  <Employee>
   <name>anil Sharma</name>
     <address>Mohali</address>
  </Employee>
  <Employee>
     <name>test</name>
     <address>india</address>
  </Employee>

</EmployeeList>
 
 In html
 
 
<script type="text/javascript">


        $(document).ready(function(){
           
            $.ajax({
                type: "GET",
                url: "employee.xml",
                dataType: "xml",
                success: function(response){
                    var htmldata="";
                    $(xml).find('employee').each(function(){
                       htmldata  +="<div>"+  $(this).find('name').text() +"</div>";
                       htmldata  +="<div>"+  $(this).find('address').text() +"</div>");
                       
                    });
                    $("#empResult").html(htmldata)
                },
                error: function() {
                    alert("An error occurred ");
                }
            });
        });
 
 
 
 
<div id="empResult"></div>
         <div>

No comments:

Post a Comment

http://blogsiteslist.com