This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Struts and the fly likes AJAX query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "AJAX query" Watch "AJAX query" New topic

AJAX query

fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
I am using ajax with struts and i open a .do action. In the action i need to write some data on the response and let it go for the callback method of ajax to catch it.

First, responseXML is giving blank on the call back method in AJAX.
Second, responseText is not giving the value i am writing on the response from server side. I think there is something wrong in writing from the server.

I have written the below code:

PrintWriter out=response.getWriter();
out.print("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");

I return success from my action which has the forward path to the same jsp from which request came.

This is my javascript side code :

function parseDataRetrieved(){
alert("this is data "+ aReq.responseXML);
response = aReq.responseText;

responseText gives values but the not the ones i am writing on server side.
responseXML is blank.

Please advise with the sample code .
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
I request for XML from the server using AJAX.
After getting the response, I want to close the connection because, then on another click i want to send another request to a different URL.

But, right now the request is not going so i am thinking, this is because the previous connection did not close and hence, a new request is not getting sent.
What might be the reason and solution?
I am using struts and calling an action of struts from AJAX.

Please advise.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

This is either a Struts question (for which we have a forum) or a Javascript question (for which we have a forum) but it's not an "Other Java APIs" question, since I don't see where there are any Java APIs involved here.

I suspect this is a problem with abusing Struts, so that's the forum I will move this to.

[Jess in Action][AskingGoodQuestions]
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
you need to return null from your action class method.
I made some corrections.
If you are adding more <messages> elements, make sure that you have a root element(XML standard)

try this.

response.setHeader("Cache-Control", "no-cache");
PrintWriter out=response.getWriter();
out.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
return null;

function parseDataRetrieved(){

[ October 03, 2006: Message edited by: Vani D Bandargal ]
[ October 03, 2006: Message edited by: Vani D Bandargal ]
I agree. Here's the link:
subject: AJAX query
It's not a secret anymore!