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.

3

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.