Reputation: 2269
Im trying to redirect Ajax post in a success function
Here's the code
$.ajax({
type: "POST",
url: "/api/create-room/",
data:{
targetedUser,
},
success: function(data) {
// How to redirect in here??
}
});
Upvotes: 1
Views: 45
Reputation: 67505
You could use window.location.replace
or window.location.href
inside the success
function :
$.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
}
});
For more information you could check This post.
Hope this helps.
Upvotes: 3