title: Jquery Cross Domain AJAX Communication with PHP
body: <p>I'm trying to create a simple login system that will have the  forms and everything on one domain (Let's call it Domain A) and the PHP files on another domain (Domain B). Why? Simply because Domain A is more reliable but doesn't support PHP. I'm quite new to all this AJAX stuff, so I'm currently using the resources I've found online.</p>
  
  <p>The Jquery and Forms part of it on <strong>Domain A</strong> are as below:</p>
  
  <pre><code>&lt;form id="submit" method="post"&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Enter Information&lt;/legend&gt;  
  
  &lt;label for="fname"&gt;Name:&lt;/label&gt;  
  &lt;input class="text" id="fname" name="fname" size="20" type="text" /&gt;  
  
  &lt;label for="lname"&gt;Email:&lt;/label&gt;  
  &lt;input class="text" id="lname" name="lname" size="20" type="text" /&gt;  
  
  &lt;button class="button positive"&gt; Submit &lt;/button&gt;  &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;script&gt;
  $(document).ready(function(){  
      $("form#submit").submit(function() {  
      // we want to store the values from the form input box, then send via ajax below  
      var fname     = $('#fname').attr('value');  
      var lname     = $('#lname').attr('value');  
          $.ajax({  
              type: "POST",  
              url: "http://domainB.com/somefolder/ajax.php",  
              data: "fname="+ fname +"&amp; lname="+ lname,  
              success: function(){  
                  $('form#submit').hide(function(){$('div.success').fadeIn();});  
  
              }  
          });  
      return false;  
      });  
  });  
  &lt;/script&gt;
  </code></pre>
  
  <p>Please note that the 'lname' and 'fname' are going to represent Name and Email instead of Firstname and Lastname respectively.</p>
  
  <p>The PHP code on <strong>Domain B</strong> :</p>
  
  <pre><code>&lt;?php  
  
      // CLIENT INFORMATION  
      $uname        = htmlspecialchars(trim($_POST['fname']));  
      $umail        = htmlspecialchars(trim($_POST['lname']));  
    $uip = 12345;
    $usecret = "secret";
  //Mysql
  $con = mysql_connect("mysql.domainB.com","username","password");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  //Connect
  mysql_select_db("login_db", $con);
  //Insert user details irrespective of whether the user is a member or not to make a log kind of thing
  mysql_query("INSERT INTO log_data (Name, Email, IP_ADDRESS, Secret)
  VALUES ('$uname', '$umail', '$uip', '$usecret')");
  
  //Now check if the user is a subscriber or not
  
  
  //   mysql_query("SELECT Email, Secret FROM login_data WHERE Email='$umail' AND Secret="secret"");
  //I don't know the code to check if the user has logged in correctly
  //This is where I need you to help me
  //I need to check if the user has logged in correctly, if yes, then return a message saying //success which should be caught by Jquery and displayed as an Alert, or something
  //If the user login failed, this php code should return a failure message which again should be caught by Jquery on Domain A and displayed as an alert in the least.
  
  
  mysql_close($con);
  //end Mysql
  
  ?&gt;  
  </code></pre>
  
  <p>Things to note here - There are two tables inside the <strong>login_db</strong> database - <strong>log_data</strong> which stores the log information and the <strong>login_data</strong> which stores usernames and passwords. The variable $secret stores the user's password.</p>
  
  <p>The log_data insertion works like a charm, but its the login_data that is bugging me. Any help would be much appreciated. Thanks!</p>
  
  <p>Imag</p>