title: Ajax response in struts2 action class
body: <p>I am trying to implement ajax in jsp(avoid form submit) using struts2. I used ajax code to pass request via url to struts2 action. But the response from struts2 is not get populated in jap. Its showing "null" value. My code to call a action in jsp using AJAX is as Follows.</p>
  
  <pre><code>    function ajaxEditFunctionCall(){  
   var xmlHttp;
       var url = "ajaxcall.action?stateName="+frm.stateName.value;  
    try{   
      xmlHttp=new XMLHttpRequest();   
    }catch (e){
        try{ 
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        }catch (e){ 
            try{  
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
              }catch (e){
                  alert("Your browser does not support AJAX!");
                  return false;
              }
        }
    }
    alert(1);
    xmlHttp.onreadystatechange = showMessage; 
        alert(2);
  
    xmlHttp.open("GET", URL, true); 
  
         alert(3);
         xmlHttp.send(null);  
    }
  
        function showMessage() { 
         alert("Inside Show Message1");
           alert(xmlhttp.readyState);
               if(xmlhttp.readyState==4)  
              { 
               alert("Inside Show Message2&amp;ReadyState4");
                   alert(xmlhttp.responseText);  
              }  
         }  
  
     Included following code in Action Class:
  
  public String ajaxcall() throws Exception{
  
       System.out.println("Inside AjaxCall");
       String errorXml = "This is a Sample to Check";  
  
       response.setContentType("text/html"); 
       response.setHeader("Cache-Control", "no-cache"); 
           response.setContentType("text/html");   
       response.getWriter().write(errorXml); 
  
       return null;
  
  }
  </code></pre>
  
  <p>Code included in Struts.xml:</p>
  
  <pre><code>  &lt;action name="ajaxcall" class="com.logic.action.CustomerAction" method="ajaxcall"&gt;
         &lt;result name="success" &gt;/pages/customer/addCustomer.jsp&lt;/result&gt; 
     &lt;/action&gt;
  </code></pre>
  
  <p>I think the error is in the action class-response statement and in struts.xml. Can any one please help me to fix this issue. Thanks in Advance.</p>