• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX query

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic