Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX ResponseXML not working

 
Steve Renard
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • 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..
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me resolve this..
My SERVER SIDE CODE:

I still see the responseXML as null.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic