struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: struts2 json return to front
Date Sat, 01 Nov 2014 02:41:36 GMT
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_thorn_bird@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";
> >      }
> > }
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message