Friday, 30 January 2015

Not able to get the xml data into the responseXML in AJAX



I am trying to get the xml data from a jsp into the AJAX function. I only getting the xml as responseText but not as responseXML. It is showing the null value in responseXML. This is the xml data of the jsp.



<%@ page contentType="text/xml" %><?xml version="1.0" encoding="UTF-8"?>
<%@taglib uri="http://ift.tt/QfKAz6" prefix="c" %>


<itemslist>
<c:set var="itemCodeVal" value='<%=request.getAttribute("itemDetails")%>'/>
<c:forEach items="${itemCodeVal}" var="entry">
<item>
<item_id>
${entry.iItemId}
</item_id>
<item_code>
${entry.strItemCode}
</item_code>
<item_name>
${entry.strItemName}
</item_name>
<price>
${entry.dPrice}
</price>
</item>
</c:forEach>


And this jsp is returning to the jsp which contains the AJAX function.



if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)
{

var xmlDoc = xmlhttp.responseText;
alert(xmlhttp.responseXML);
txt = "";
x = xmlDoc.getElementsByTagName("item");
for (i = 0; i < x.length; i++)
{
txt = txt + x[i].childNodes[0].nodeValue + "<br>";
}
alert(txt);



}
}
xmlhttp.open("GET", urls, true);
xmlhttp.send();


I'm not getting that xml here as responseXML but getting as reponseText. Can you Please help me how to resolve this issue.


Thanks in Advance Manoj Kumar


No comments:

Post a Comment