I'm having problems with an Ajax Request between SubDomains.
The PHP Script that handle the request is located at account.domain.com/login
And i have many other SubDomains, the Ajax request can be called in every SubDomain.
Here is the Javascript currently i have:
$.ajax({
type: "POST",
url: "http://account.domain.com/login",
data: "username=" + username + "&password=" + password + auto,
crossDomain: true,
}).done(function(data){
alert(data);
//window.location.replace(data);
});
The problem is that if i call this when i'm on another sub domain that is not account.domain.com
, the script fails. (Not showing alert).
I have checked with Tamper Data to see if the request has been made, and it is, with Response Header State 200.
PHP:
//Process Login
if(count($_POST)){
$username = isset($_POST['username']) ? $_POST['username'] : false;
$password = isset($_POST['password']) ? $_POST['password'] : false;
$auto = isset($_POST['auto']) ? true : false;
$main->login($username,$password,$auto);
if($main->has_error()){
$_SESSION['NoteMsgs'] = $main->error();
$return = $main->link['login'];
}else{
//PHPBB Login
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if($user->data['is_registered']){
//User is already logged in
}else{
$result = $auth->login($username, $password, $auto);
if ($result['status'] == LOGIN_SUCCESS){
//User was successfully logged into phpBB
}else{
//User's login failed
}
}
if(isset($_POST['returnUrl'])){
$return = filter_var($_POST['returnUrl'], FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
if($return == $main->opt['http_root'] or $return == $main->opt['http_root'].'/' or $return == $main->link['login'] or $return == $main->link['login'] .'/'){
$return = $main->link['return'];
}
}else{
$return = $main->link['return'];
}
}
echo $return;
exit;
}
What could be the problem? Thank you.