I need to redirect to another page in my PHP code on an AJAX call. The only thing I can seem to find online about this is to do it through JavaScript using window.location.href = 'url';
but it does not work.
If I try to redirect using the window.location.href
to profile.php?user=person
then it has the url localhost/profile.php?user=person
but if I type in the full URL for the redirect like project/login/profile.php?user=person
then it stays on the same page. The profile.php
page only echo's what who the user in the url is.
Any ideas?
Here is my code:
$.ajax({
url: 'processes/login.inc.php',
type: 'post',
data: data,
success: function(res) {
if(res != '4502') {
var s = 'profile.php?user='+res;
window.location.href = s;
}
}
});
and the PHP:
<?php
require_once('../core/init.php');
$username = escape($_POST['ul']);
$password = escape($_POST['pl']);
$user = new User();
$login = $user->login($username, $password);
if($login) {
// Redirect::to('../profile.php?user='.$username);
echo $username;
} else {
echo '4502';
}