I am trying to redirect a user after login to a specific page but it's not getting redirected, I tried checking everything but the issue still exists. i get this error like the page name gets in red color in network section of inspect element.
i used the following code:
$("#form-login").submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "includes/ajax_functions.php",
data: $(this).serialize()+"&action=form-login",
dataType: "json",
success: function(data)
{
window.location.replace(data.redirect_url);
}
});
});
ajax file contain the following code
$json = array("status" => 2, "message" => 'Successfully LoggedIn', "redirect_url" => site_url('dashboard'), "role" => $role);
and the site url function is as follows
function site_url($urlParam) {
return SITE_URL.(($urlParam!="")?$urlParam:"");
}
please provide me the solution that how it will be redirected and where i'm going wrong.
The replace
function returns a string , IE Strings are immutable and their methods do not change their value.
So, window.location.replace(data.redirect_url)
would not actually change the window.location
. Also, keep in mind that window.location is an object , not a string. However, if you did window.location.href = data.redirect_url;
You would redirect to data.redirect_url
.
Good luck!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.