I want to retrieve XML data in HTML in table format. I tried using ajax but data is not coming. Here what might be the issue can anyone help me out. I new to ajax. Feel free to tell anything wrong in my code. Below is the image I want to like this
$(document).ready(function() {
$(window).load(function () {
$.ajax({
type: 'GET',
url: '2.xml',
dataType: 'xml',
success: function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Artist</th><th>Title</th></tr>";
var x = xmlDoc.getElementsByTagName("Row");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("Process")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Product")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("Operation")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("Description")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("Batch")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("QTY")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("PlannedSchedule")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("ActualSchedule")[0].childNodes[0].nodeValue +
"</td></tr>" +
x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="demo"></table>
XML:
<Rowsets>
<Rowset>
<Row>
<Process>70787863</Process>
<Product>600033</Product>
<Operation>Operation goes here</Operation>
<Description>Operation description goes here</Description>
<Batch>259</Batch>
<QTY>999</QTY>
</Row>
<Row>
<Process>707863</Process>
<Product>6033</Product>
<Operation>Operation goes here</Operation>
<Description>Operation description goes here</Description>
<Batch>249</Batch>
<QTY>99</QTY>
</Row>
</Rowset>
</Rowsets>