aspose file tools*
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
Author

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:
response.setContentType("text/xml");

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

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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out=response.getWriter();
out.flush();
out.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<message>");
out.println("fahad");
out.println("</message>");
return null;

function parseDataRetrieved(){
alert(aReq.responseXML);
alert(aReq.responseText);

[ October 03, 2006: Message edited by: Vani D Bandargal ]
[ October 03, 2006: Message edited by: Vani D Bandargal ]
 
 
subject: AJAX query