• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX ( problem while retrieving xml data from the jsp)

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic