I created a login page with jQuery, I'm sending Ajax request by .getJSON(),
Also, I want to use struts 2's controller to assign to different pages based
on the returned results of action (in this case, if username and password
doesn't match, use an ajax reminder; if match, redirect to another page, say
selectBook.jsp)

in struts.xml, I used 

[code]          <action name="Login" class="tutorial.LoginDataAction">
            <result name ="success"
type="json">/pages/selectBook.jsp</result>
            <result name="failed" type="json"/>
        </action>  
 [/code]

However, it doesn't work (means if the username and password match, it
wouldn't go to page selectBook.jsp).

With google, I know I can solve it in this way: In login.jsp, 
[code]                  function login()
                {
                        var unameval = $("#username").val();
                        var pwordval = $("#password").val();
                        $.getJSON("Login.action", {username:unameval, 
password:pwordval},
getData);
                }

                function getData(json) 
                {
                        var data = json;
                if(data.redirect == 1)
                    top.location.href="/Test/pages/selectBook.jsp";//redirection
                else
                        $("#status").html(data.comment);;                       
                }
[/code]

The problem is, in this way, the controller doesn't determine the redirect
page, which is not what struts 2 should be.

Any suggestions about this issue, instead of the method above(change
callback function of login.jsp based on json data)? Thanks!
-- 
View this message in context: 
http://www.nabble.com/how-to-use-struts-2-to-redirect-jQuery-Ajax-request-tp23605756p23605756.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to