Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Java Object as JSON response using Jquery AJAX

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.

like image 486
Tushar Avatar asked Jan 17 '26 10:01

Tushar


1 Answers

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.

like image 86
Tushar Avatar answered Jan 20 '26 00:01

Tushar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!