简体   繁体   English

AJAX验证成功后的Struts2需要重定向到另一个页面

[英]Struts2 after AJAX validation success need to redirect to another page

I am not using struts2-jquery-plugin .not using struts2-jquery-plugin Only using struts2-json-plugin with JQuery latest.struts2-json-plugin with JQuery最新的struts2-json-plugin with JQuery使用struts2-json-plugin with JQuery

Want to redirect/actionredirect to another page after successful validation.希望在成功验证后redirect/actionredirect到另一个页面。 If I do it like <result type="redirect">/quiz-success.jsp</result> OR <result>/quiz-success.jsp</result> is not working.如果我像<result type="redirect">/quiz-success.jsp</result>或者<result>/quiz-success.jsp</result>不起作用。

Question: How do you guys do it?问题:你们是怎么做到的?

1 - Is it possible to do redirection etc in struts.xml during AJAX request?
2 - I have to redirect/page refresh in $.ajax({ success: function (data) {} }); like below?

$.ajax({
                    url: url,
                    type: 'POST',
                    data: viewData,
                    //dataType: "json",
                    cache: false,
                    complete: postValidation,
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("error :"+XMLHttpRequest.responseText);
                    },
                    success: function (data) {
                        Window.location = "/cms/home.action"+sessiontoken;
                    }
                });

struts.xml struts.xml

<package name="validation" namespace="/validation" extends="json-default">
        <action name="quizAjax" class="com.myapp.action.QuizAction" method="sayHi">
            <interceptor-ref name="jsonValidationWorkflowStack"/>
            <result name="input">/quiz-ajax.jsp</result>
            <result type="redirect">/quiz-success.jsp</result>
        </action>
    </package>

You can't use the <result type="redirect">/quiz-success.jsp</result> because you are calling the server using javascript.您不能使用<result type="redirect">/quiz-success.jsp</result>因为您正在使用 javascript 调用服务器。 It's the script that gets the answer from the server, not the page so you have to handle it in your script.这是从服务器获取答案的脚本,而不是页面,因此您必须在脚本中处理它。

change this line and see if this works for you:更改此行,看看这是否适合您:

change this改变这个

Window.location = "/cms/home.action"+sessiontoken;

to this对此

window.location.replace(window.location.href+"/cms/home.action"+sessiontoken);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM