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