Thanks for the reply. I thought that the submit might be the problem. I have a regular <s:submit/> button doing the submit. I tried just using a <input type="button" /> with an onClick action that was something like onclick="document.forms[0].submit();" That produced the same result. I also tried calling the JS method that does the ajax post directly. onclick="javascript:mySubmitFunction()" where the function below is mySubmitFunction(). In that case the JS function could not be found. I'm not sure why this is.
It might be worth mentioning that the entire page/form is in an iframe overlayed on a parent window? The mySubmitFunction() is in an included .js file that is in the file source, but not found when invoked from the onclick of the button. They only way I could get the form to submit and call the JS method is by binding to the submit action. $(document).ready(function() { $("#stutsFormAction").bind("submit", function() { mySubmitFunction(); }); }); I'm pretty sure the problem is related to the submit, but not sure how to go about debugging or fixing. On Mon, Apr 26, 2010 at 11:50 PM, Rahul Mohan <rahul.mo...@tcs.com> wrote: > Hi, > > Is your intention to show the message 'success' in the results div? In > that case you don't need a JSON response. > > Also, is jsonData an instance variable of your action class. Otherwise, > your json result will simply return an empty json. You can verify the > response by opening the response in a text editor when the browser dialog > pops-up. > > If json is what you want, I see two probable causes: > 1. The browser is also doing a normal submission - i.e after your ajax > post, the form is also getting submitted normally. If you are using > firefox with firebug, you can put a breakpoint on the response handler to > see if this is the case. ( Also, put an ajax error handler and put a break > point there too. Its easier for debugging. ) > > 2. The response content type is not understood by browser. This can happen > if your response has formatting errors. For JSON response, the best > possible way in jQuery would be http://api.jquery.com/jQuery.getJSON/ > > - Rahul > > > > From: > Ozu Natsu <ozu.na...@gmail.com> > To: > user@struts.apache.org > Date: > 26-04-2010 20:02 > Subject: > JSON Plugin Question > > > > Hello, > > I am trying to use the JSON plug-in for the first time. I have a form > that uses jquery to submit to a struts2 action, the action is being > invoked properly and I am trying to send result back to call back > function, but when result returns the browser prompts me to save or > open the result file. I expeced the result to be sent to my call back > function, which appears to not be invoked. > > I am using Stuts 2.1.8.1 > > What am I doing wrong? > > My form is submitted as such: > function submit(){ > > $.ajax({ > type : "POST", > cache : false, > url : > "./myaction.do", > data : $(this).serialize(), > success: function(json) { > $("#result").html(json); > } > }); > > return false; > } > > My action is configured in the struts.xml: > > <package name="mypkg" namespace="/def" > extends="json-default"> > <action name="addNote" class="..myClass" > method="addData"> > <result type="json"> > <param name="root">jsonData</param> > </result> > </action> > </package> > > In the action/method I have a hashmap that I am putting result into: > > Map<String, String> jsonData= new HashMap<String,String>(); > jsonData.put("result", "success"); > > Any reply appreciated. Thanks in advance! > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > > =====-----=====-----===== > Notice: The information contained in this e-mail > message and/or attachments to it may contain > confidential or privileged information. If you are > not the intended recipient, any dissemination, use, > review, distribution, printing or copying of the > information contained in this e-mail message > and/or attachments to it are strictly prohibited. If > you have received this communication in error, > please notify us by reply e-mail or telephone and > immediately and permanently delete the message > and any attachments. Thank you > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org