Javascript 如何在Ajax帖子中重定向?
我试图在一个成功函数中重定向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({
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
相同。是的,它们引用的是相同的东西,只是稍微短了一点(:重定向到哪个位置?