Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Ajax帖子中重定向?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何在Ajax帖子中重定向?

Javascript 如何在Ajax帖子中重定向?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我试图在一个成功函数中重定向Ajax帖子 这是密码 $.ajax({ type: "POST", url: "/api/create-room/", data:{ targetedUser, }, success: function(data) { // How to redirect in here?? } }); 您可以在success函数中使用window.location.replace或window.locati

我试图在一个成功函数中重定向Ajax帖子

这是密码

$.ajax({
    type: "POST",
    url: "/api/create-room/",
    data:{
      targetedUser,
    },
    success: function(data) {
      // How to redirect in here??
    }
});

您可以在
success
函数中使用
window.location.replace
window.location.href

$.ajax({
    type: "POST",
    url: "/api/create-room/",
    data:{
        targetedUser,
    },
    success: function(data) {
        window.location.replace("url"); //Simulate HTTP redirection
        //Or
        window.location.href = "url"; //Simulate click on a link
    }
});
有关更多信息,请查看


希望这能有所帮助。

您可以解释这两个选项之间的区别。或者只是
window.location='url'
。感谢@michael的干预,
window.location
window.location.href
相同。是的,它们引用的是相同的东西,只是稍微短了一点(:重定向到哪个位置?