This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes AJAX ( problem while retrieving xml data from the jsp) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "AJAX ( problem while retrieving xml data from the jsp)" Watch "AJAX ( problem while retrieving xml data from the jsp)" New topic
Author

AJAX ( problem while retrieving xml data from the jsp)

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
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..


Abhishek
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56547
    
  14

Why on earth are you inlcuding HTML markup in your XML? Just return an XML response.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
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....
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: AJAX ( problem while retrieving xml data from the jsp)
 
Similar Threads
Expand / Collapse of div elements
I-frame within a jsp page
A problem in hiding a button
dojo and javascript DOM issue
assign values to form elements dynamically?