3

I am new to Jquery,Struts2 and Ajax.

I am trying to retrieve a Java object to Jquery Ajax , via Struts2 Action class. I am receiving the response as [object Object]

$.ajax({
/* type : "POST", */
url : "launchapptest",
/* contentType: "application/json; charset=utf-8", */
data : "processDateInput="+processDate,
dataType : "json",
async: true,
success : function(result) {
 alert(result);
 alert("Success");     
 }
});

My Action Class:

 public class LaunchAppTestAction extends ActionSupport {

private static final long serialVersionUID = -367986889632883043L;

//private ProcessDate pd = new ProcessDate();

 private Object od;

private String processDateInput=null;   


public String execute() throws Exception {

    OverviewService os = new OverviewService();
    System.out.println("Action Class" +processDateInput);

    List<?> overviewList = os.getOverViewDetails(processDateInput); 

    setOd(overviewList);

    return SUCCESS;
}

public String getProcessDateInput() {
    return processDateInput;
}

public void setProcessDateInput(String processDateInput) {
    this.processDateInput = processDateInput;
}

 public Object getOd() {
        return od;
    }

    public void setOd(Object od) {
        this.od = od;
    }}

My struts.xml looks Like :

    <action name="launchapptest" class="com.ge.wd.action.LaunchAppTestAction">
        <result name= "success" type="json">
        </result>
    </action>

Please let me know how can I access the object Od in the the Jquery Ajax.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Tushar
  • 1,450
  • 6
  • 18
  • 30
  • 2
    Learn to use [`console.log()`](https://developer.mozilla.org/en-US/docs/Web/API/Console.log), remember `alert` is not debugging tool, event https://developer.chrome.com/extensions/tut_debugging might help – Satpal Nov 12 '14 at 07:57
  • `result.od` or as suggested by Satpal, always try debugging with dev tools in chrome/FF. – Jai Nov 12 '14 at 08:07
  • http://stackoverflow.com/questions/16941148/parsing-java-map-returned-as-json-response-using-javascript See this – Pravat Panda Nov 26 '14 at 17:05

1 Answers1

2

Thanks for your help, I was able to debus the issue with help of chrome developer tools.

I changed my Jquery script to use stingify function.

$.ajax({
            /* type : "POST", */
            url : "launchapptest",
            /* contentType: "application/json; charset=utf-8", */
            data : "processDateInput="+processDate,
            dataType : "json",
            async: true,
            success : function(result) {                
                var od = JSON.stringify(result) ;
                console.log(od);
            }
        });

I was able to view the JSON object on console. Thanks for all the help.

Tushar
  • 1,450
  • 6
  • 18
  • 30