Hi i need your help on ajax with struts what i did is i have a text box and a select box with one button what i want to do is i enter a value in the textbox then after press the button that value shuld be inserted in the data base and also displayed in the select box . i can able to update the data base and create response like this ***************************************************************
here is my action class:--- try { l_CatalougeImpl.addEcardCatagory(idField);// for data base insertion
String value_idField=idField.trim();//get the value here in the idField variable
StringBuffer l_stringBuffer= new StringBuffer(); l_stringBuffer.append("<catagory>"); l_stringBuffer.append("<CatagoryName>"+idField.trim()+"</CatagoryName& gt;"); l_stringBuffer.append("</catagory>"); addCatagory=true;
}catch(Exception e) { return mapping.findForward("error"); } return mapping.findForward("ecards.TestAJAX"); // it will forward to some jsp page as per struts-config.xml mapping } ***************************************************************************** **** Here is my JSP code:-- <%@page contentType="text/html" %> <%@ taglib uri="../WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="../WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="../WEB-INF/struts-logic.tld" prefix="logic" %> <html:html> <head> <title><bean:message key="Ecards.SendEcardForm.title"/></title> <script> var req; var catagory; function validate() { var idField=document.getElementById("card_name"); var url = "<%=request.getContextPath()%>/ajaximpl.do?id=" +idField.value; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("GET", url, true); req.onreadystatechange = callback; req.send(null); } function callback() { if (req.readyState == 4) { //alert("Ajax response:"+req.responseText); if (req.status == 200) { alert("update dom"); parseMessages(); } else { alert("Ajax response:"+req.stutsText); } } } function parseMessages() { alert("inside the parsing Message"); var xml=req.responseXML;// Here i got the nulll value alert("inside while loop"); var catagories=xml.getElementsByTagName("Catagories"); alert("catagories:--"+catago ries); if(catagories !=null) { var catagoryId=catagories.childNodes; if(catagoryId !=null) { catagory=catagoryId.getElementsByTagName("CatagoryName"); } else { al ert("catagoryId has no value"); } } else { alert("catagories has no value"); } } alert("catagory value is :--"+catagory); </script> </head> <body bgcolor="#FFFFFF"> <!-- Start: template code Vikas Sheel Gupta 22nd Dec 05 --> <Center> <table border="0" cellpadding="0" cellspacing="0" height='559' width='779'> <tr> <td valign="top" height='60'><jsp:include page="/header.jsp"/> </td> </tr> <tr> <td valign="top" height='439'> <!-- Start : Vikas Sheel Gupta Code to display card and card contents --> <html:form action="/ajaximpl"> <table> <tr><td><bean:message key="Ecards.SendEcardForm.catagory" /></td> <td> <!-- code for card catagory--> <logic:present name="Array_ecardlist" scope="request"> <html:select property='catagory' > <html:options collection="Array_ecardlist" property="m_strCategoryId" labelProperty="m_strCategory_Name" /> </html:select> </logic:present> <!-- End of code for card catagory--> </td> </tr> <tr><td><bean:message key="Ecards.SendEcardForm.card_name" /></td> <td> <html:text property="card_name" /> </td> </tr> <tr> <td> <html:button property="button" onclick="return validate()"><bean:message key="button.save"/></html:button> </td> </tr> </table&g t; </tr> </table> </html:form> <!-- End : Vikas Sheel Gupta Code to display card and card contents --> </td> </tr> <tr> <td valign="top" height='60'><jsp:include page="/header.jsp"/></td> </tr> </table> </Center>
<!-- End: template code--> </body> </html:html>
********************************** ***************************** Now my problem is when i call the parseMessages() function in java script then my req.responseXML is null i cant under stand why this happens can u pls tell me why this happend i shall be thank ful to you