使用 ajax 时,如何在 jQuery/JavaScript 中创建重定向页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18032534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 10:32:30  来源:igfitidea点击:

How can I make a redirect page in jQuery/JavaScript when using ajax?

javascriptjqueryredirect

提问by Anton Dimitrov

How can I redirect the user from one page to another using jQuery -> Ajax? Thanks for your time.

如何使用 jQuery -> Ajax 将用户从一个页面重定向到另一个页面?谢谢你的时间。

回答by Uttam K C

Try this if you want to redirect to another page once ajax call is success,

如果您想在 ajax 调用成功后重定向到另一个页面,请尝试此操作,

    $.ajax({
    url: "page1.html",
    success:function(result){
        document.location.href="page2.html";
    }});

回答by dbanet

    $.ajax({
        url:"http://where.to/redirect",,
        async:false,
    });

This will load the url synchroniously, that means redirect the user "in jquery/javascript when using ajax". To "make a redirect page", write this:

这将同步加载 url,这意味着在“使用 ajax 时在 jquery/javascript 中”重定向用户。要“制作重定向页面”,请这样写:

    <script type="application/javascript" language="javascript">
    $.ajax({
        url:"http://where.to/redirect",,
        async:false,
    });
    </script>

... tada! We have a "a redirect page in jQuery/JavaScript when using ajax"! ;)

……多多!我们有一个“使用 ajax 时在 jQuery/JavaScript 中的重定向页面”!;)

回答by Arun Prasath

// Through an HTTP redirect

// 通过 HTTP 重定向

window.location.replace("http://stackoverflow.com");

window.location.replace(" http://stackoverflow.com");

// Through by clicking on a link

// 通过点击链接

window.location.href = "http://stackoverflow.com";

window.location.href = " http://stackoverflow.com";