Announcement Announcement Module
Collapse
No announcement yet.
AJAX response not coming from spring action class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX response not coming from spring action class

    i am executing AJAX call to spring flow action class but the response is not coming to jsp.i am getting error at the client side.
    do i need to set application.json in action class.if yes how?


    Code:
       sample.jsp.
        ************
         $.ajax({	
    						url: "${flowExecutionUrl}&_eventId=proceed",
    						dataType: "json",
    						data: $('#frm').serialize()+"&ssn="+$("#ssn").val(),
    						contentType: "application/json; charset=utf-8",
    					    success: function(data){ 
    							   alert(data.employees.length)
    						         alert("success")  
    								},   
    							error: function(e, xhr){ 
    								   alert("error");
    							}
    					});
    
    flowAction.java
    ****************
    public String  generateCode(RequestContext context) {
        	StringBuffer emps =null;
    	
        	try {
        		  String name = context.getExternalContext().getRequestParameterMap().get("name");
        		  String ssn = context.getExternalContext().getRequestParameterMap().get("ssn");
        		  String zipcode = context.getExternalContext().getRequestParameterMap().get("zipcode");
        		  emps = new StringBuffer();
    		  emps.append("{\"employees\":\"ABCD\"}");
    		 context.getExternalContext().getResponseWriter().write(emps.toString());				
    			
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    		System.out.println("emps....emps........."+emps.toString());
    		return "success";
        }
    
    
     
    
    flow.xml
    *********
    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/webflow
    http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
    <view-state id="sample" view="samle.jsp">
    		<transition on="proceed" to="save"/>
    	</view-state>
    	
    	   <action-state id="save"> 
            <evaluate expression="flowAction.generateCode(flowRequestContext)" /> 
    		 <transition on="success" to="sample" /> 
            </action-state> 
    </flow>
Working...
X