posted 19 years ago
my server side response code
[code]
resp.setContentType("text/xml");
resp.setHeader("Cache-Control", "no-cache");
resp.getOutputStream().println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
resp.getOutputStream().println("<response>");
resp.getOutputStream().println("<result>" +" testPassed" + "</result>");
resp.getOutputStream().println("<result>" +" testPassed2" + "</result>");
resp.getOutputStream().println("<result>" +" testPassed3" + "</result>");
resp.getOutputStream().println("</response>");
resp.getOutputStream().println("\n\n");
[\code]
client side
javascript
[code]
<script language="javascript">
var theURL = "http://localhost:9080/deploy/HttpServ";
var http = getHTTPObject();
function handleHttpResponse() {
if (http.readyState == 4) {
// var response = http.responseXML.documentElement;
// var result = response.getElementsByTagName('result')[0].firstChild.data;
// result = unescape(result);
// alert("message received"+ result);
var items = http.responseXML.getElementsByTagName("result");
var result ="";
for (var i = 0; i < items.length; i++) {
alert("message length"+items.length);
// result = http.getElementsByTagName('result')[i].firstChild.data;
alert("message received"+ items[i]);
}
// var str = http.responseText;
// alert("message received"+str);
}
}
function updateform() {
http.open("GET", theURL, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
</script>
[\code]
i am getting the length as 3 in the first alert ..but i am not able to get the value of the message in the second alert i.e items[i]
can any one help me out
thanks in advance