title: Remote Ajax Request
body: <p>I'm trying to make a Ajax request form my local machine to a website that houses my php file.  There is only one file in the site right now the php.  It works fine when the files are in the same folder but it won't do anything when the url points to my web url.  How do I get my JS to talk to the php on a server.  Also, I know this code sucks.  It an example I'm working with.  </p>
  
  <pre><code> $('#btn').click(function(){
              //pull vars 
  
              var username = $('#username').val();
              var password = $('#password').val();
  
              //request for username
              $.post("Main URL", {user:username,pass:password}).done(function(data){
                  $("#loginMessage").html(data);
              }); 
  
          });
  </code></pre>
  
  <p>php side on hosting server</p>
  
  <pre><code>if($_SERVER["REQUEST_METHOD"] == "POST")
  {
      //assign vars after formatting to avoid a wrong login with correct 
      //username and password
      $username = trim($_POST["user"]);
      $password = trim($_POST["pass"]);
  
      //specfic message
      $errorMessage = "The username ".$username." or the password ".$password. " is wrong";
      $welcomeMessage = "Welcome ".$username;
  
      //user name or pass word is wrong invovke failure html
      if($password != "1234" || $username != 'Adin')
      {
          include("html.html");
          echo('&lt;message&gt;'.$errorMessage.'&lt;/message&gt;');
      }
  
      //username and password is right invoke the html with proper messages
      if($password == "1234" &amp;&amp; $username == "Adin")
      {
          include("html.html");
          echo('&lt;message&gt;'.$welcomeMessage.'&lt;/message&gt;');
      }
  
  
  }
  </code></pre>