Getting Java object as JSON response using JQuery AJAX
I am new to JQuery, Struts2 and Ajax.
I am trying to get Java object in JQuery Ajax through Struts2 Action class. I get 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 I can access the Od object in JQuery Ajax.
+3
source to share
1 answer
Thanks for your help, I was able to debut using chrome developer tools.
I modified my JQuery script to use the 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 in the console. Thanks for the help.
+2
source to share