File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes AJAX help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "AJAX help needed" Watch "AJAX help needed" New topic
Author

AJAX help needed

murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
i am posting total JavaScript code here

var req = false;

function validate()
{
var idField = document.getELEmentById("userid");
var url = "/WebApp/Actopm/MAPPING-1?id="+escape(idField.value);
if(windows.XMLHttpRequest)
{
req = new XMLHttpRequest();
}else if(window.ActiveXObject)
{ try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{ try{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch((e)
{
}
}
}//end else

req.open("GET" , url , true);
req.onreadystatechange = function() { replyMethod(); };
req.send(null);

}//end function


function replyMethod()
{ if(req.readyState == 4)
{
if(req.status == 200)
{
alert(req.responseXML);
}
}
}//end function


the XML code generation in Action class perform() method is like

StringBuffer buffer = new StringBuffer();
buffer.append("<?XML version=\"1.0\" encoding=\"UTF-8\"?>");
buffer.append("\n");
buffer.append("<root>");
buffer.append("\n");
buffer.append("<labelValueBean>");
buffer.append("\n");
buffer.append("<label>name</lable>");
buffer.append("\n");
buffer.append("<value>John</value>");
buffer.append("\n");
buffer.append("</labelValueBean>");
buffer.append("\n");
buffer.append("</root>");
response.getWriter().write(buffer.toString());

return mapping.forward("succes");

here success is mapping to some jsp which contains some html stuff.

when i print req.responseText in JavaScript givings the html stuff of the success jsp. and req.responseXML giving NULL.


NOTE: if the above stuff ( generating XML code ) is written in ScriptLet of some other jsp to handle the request , now if i print the req.responseText in JavaScript giving the XML content which i have generated, and req.responseXML giving same NULL.

I CAN NOT UNDERSTAND WHY THE req.responseXML giving NULL.
Please i want solution for this ,

NO one is giving proper reponse or suggestions.
Pradeep Swaminathan
Greenhorn

Joined: Aug 25, 2005
Posts: 8
Murali,

I had a similar issue.... Try returning Null in
"return mapping.forward("succes"); "


Pradeep
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi Pradeep,

you are right , i used

return mapping.findFoward("Null"); in perform method of Action class.

in JavaScript when i print the request.responseText now it is giving the XML content what i am writing into response.

but Still i am getting null for request.responseXML

still my problem not resolved.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
BTW, I am pretty sure that Pradeep meant "return null;" instead of "return mapping.findFoward("Null");" Unless you actually have a forward named "Null" both of these will results in the exact same behavior, returning a value of null, but calling findForward is not needed.

- Brent
 
GeeCON Prague 2014
 
subject: AJAX help needed