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


Reply via email to