• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX ( problem while retrieving xml data from the jsp)

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a simple ajax application which will get the xml data from the jsp.
I created a String Buffer in jsp which holds xml tags...and iam getting the error while retrieving xml data in javascript..but iam getting the data correctly when there is no html content in the jsp.
Can any one help how to ignore html data while parsing xml content...

here is the sample application...

<html>
<body>

<script language="javascript">
var button="";
var img="";
var xmlHttp;
function doThis(value,tick)
{
button=value;
img=tick;
submitRequest();
}

function submitRequest()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="add.jsp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var response=xmlHttp.responseXML;
var tools=response.getElementsByTagName("tools")[0].childNodes[0].nodeValue;
if(tools=='added')
{
document.main.elements[button].value=tools;
document.main.elements[button].disabled=true;
document.getElementById(img).style.display="block";
}
}
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

</script>

<form name="main" action="get">
<img id="tick1" src="tick.gif" style="display:none"/><input type="button" name="one" value="add" on click="doThis('one','tick1')"/>
<img id="tick2" src="tick.gif" style="display:none"/><input type="button" name="two" value="add" on click="doThis('two','tick2')"/>
<img id="tick3" src="tick.gif" style="display:none"/><input type="button" name="three" value="add" on click="doThis('three','tick3')"/>
<img id="tick4" src="tick.gif" style="display:none"/><input type="button" name="four" value="add" on click="doThis('four','tick4')"/>
</form>
</body>
</html>

here is my jsp page---------add.jsp-------

<html>
<body>
<%
StringBuffer buf=new StringBuffer();
buf.append("<tools>");
buf.append("added");
buf.append("</tools>");
response.setContentType("text/xml");
System.out.println("..."+buf);
response.getWriter().write(buf.toString());
%>
<body>
</html>

-----------------------
when i remove the html tags from jsp it is working otherwise it is not...why it is so happening..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth are you inlcuding HTML markup in your XML? Just return an XML response.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is there is some worm in the system which automatically including a iframe in the jsp and iam not getting response..
thats why i have asked is there any way to get only xml data....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic