You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Martin Gainty <mg...@hotmail.com> on 2014/11/01 03:41:36 UTC
RE: struts2 json return to front
Lee
> Date: Tue, 28 Oct 2014 22:04:14 -0400
> Subject: Re: struts2 json return to front
> From: jlmagc@gmail.com
> To: user@struts.apache.org; sh_thorn_bird@yahoo.com
>
> Have you tried to use firebug or some http proxy or sniffer to check the
> reponse sent to the browser?
>
> 2014-10-28 20:50 GMT-04:00 john lee <sh...@yahoo.com.invalid>:
>
> > After click the button, the value of partid is passed to action
> > class, and see the output '123' from the console. the assigned value of
> > dummymesg is displayed on the console as well.
> > but the dummymesg never return to front javascript. looks like success
> > or error function call never be called,
> > please advise
> > thanks in advance
> >
> >
> >
> > Cart.jsp
> > <script type="text/javascript">$(function() {
> > $("#deleteButton").click(function(){
> > $.ajax({
> > type: "POST",
> > url: "cart-del!del.action",
> > data: {'partid':'123'},
> > dataType:"json",
> > success: function(json){
> > console.log("return success");
> > var obj = $.parseJSON(json);
> > alert("dummey mesg="+obj.dummymesg);
> > return false;
> > },
> > error: function(json){
> > console.log("return error = "+json);
> > alert("json=" + json);
> > return false;
> > }
> > });
> > });
> > });</script><button id="deleteButton">delete</button>
> >
> > struts.xml<package name="default" extends="json-default"> ...
> > <action name="cart-del" class="CartAction" method="del">
> > <result name="json-data" type="json"></result>
> >
> > </action>
> > </package>
> > CartAction.java
> > public class CartAction extends ActionSupport {
> > private String partid;
> > public void setPartid(String partid) { this.partid=partid.trim(); }
> > public String getPartid() { return partid; }
> >
> > public void setDummymesg(String dummymesg) {
> > this.dummymesg=dummymesg; }
> > public String getDummymesg() { return dummymesg; }
> > public String del() throws Exception {
> > dummymesg="struts function reached";
MG>del should return json formatted data e.g.MG>dummymesg="{dummymesg:"struts function reached}"
MG>Saludos Cordiales desde EEUU
> > System.out.println("cart-del, partid="+partid+"\n");
> > System.out.println("cart-del, dummymesg="+dummymesg+"\n");
> > return "json-data";
> > }
> > }