• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

AJAX ResponseXML not working

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to send an AJAX request to query table data and print response..
But the ResponseXML is showing empty..
However, ResponseText works well.
Here's my javascript function involving AJAX and down below is my server side code snippet.

function initRequest()
{
var msg = document.getElementById('msg');
msg.childNodes[0].nodeValue = "Sending request..";
document.frmData.btnSend.disabled = true;

var url = "servlet/UNExt?par=" + new Date().getTime();
var queryString = "&Type=fetch&quart=4"+
createXMLHttpRequest();
xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}

function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var msg = document.getElementById('msg');
var result = xmlHttp.responseXML.getElementsByTagName("RESPONSE")[0].firstChild.data;
if (result == "OK")
msg.firstChild.nodeValue = 'Success';
else msg.firstChild.nodeValue = 'Error';
}
}
}


SERVER SIDE CODE:
PrintWriter out = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");

out.println("<RESPONSE>" + res+ "</RESPONSE>");
out.close();

Please help..
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything looks ok to me. But what you didn't show is the XML you are sending back to the browser. I'd guess that there is something wrong with your XML and that is why you aren't getting it back. At least, that's usually what happens to me. XML probably isn't well formed. Missing closing element or missing parent elements, etc. Things to look for.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Follow this:
http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html
and you should get your problem fixed.

Eric
 
Sheriff
Posts: 67671
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
Please be sure to use UBB code tags when posting code to the forums. Please read this for more information.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the server side code in Struts Action..
I have this at the end of the code:
return actionMapping.findForward("success");
It rebuilds the matching JSP file.
Does that overwrite my Printwriter contents?.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me resolve this..
My SERVER SIDE CODE:

I still see the responseXML as null.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not have valid XML which is one of the steps in that link.

This link shows you the basic xml syntax, hopefully you see what is missing. http://www.w3schools.com/xml/xml_syntax.asp

Eric
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:
You do not have valid XML which is one of the steps in that link.

This link shows you the basic xml syntax, hopefully you see what is missing. http://www.w3schools.com/xml/xml_syntax.asp

Eric



Do we really no that? He hasn't shown his XML to us yet. But that would be the best bet.
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic