• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

XMLHttpRequest problem

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
with items[i] you are just referencing the tag.

you can try:
items[i].nodeValue
or
items[i].innerHTML

Eric
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic