title: jQuery AJAX post doesn't work on all computers
body: <p>I have a simple form that sends data using jQuery/Ajax/PHP. The PHP code validates the input before it sends it to the database and returns an error message to the response div if the input is invalid.</p>
  
  <p>It works great on my computer and on my own server. But when I upload it to the client's server it doesn't work as expected. I noticed the following when I access the page from the client's server:</p>
  
  <ul>
  <li><p>The validation result is being sent to the response div only if ALL the input fields have values. If any of the fields is empty, then nothing happens and no validation message is returned.</p></li>
  <li><p>It doesn't seem to be a machine issue because I'm using the same computer to access the 3 copies, the one on my localhost, the one on my server, and the one on the client's server.</p></li>
  </ul>
  
  <p>Here is the code; the jQuery:</p>
  
  <pre><code>$(document).ready(function() {
      $('#signup').click(function() {
          var queryString = 'ajax=true';
  
          var txtName = encodeURIComponent($('#txtName').val());  
          if(txtName.length &gt; 0){
              txtName = txtName.replace(/\%/g, '-');
          }
  
          var txtEmail = escape($('#txtEmail').val());
  
          var txtPhone = encodeURIComponent($('#txtPhone').val());
          if(txtPhone.length &gt; 0){
              txtPhone = txtPhone.replace(/\%/g, '-');
          }
  
          var txtPhoneCode = encodeURIComponent($('#txtPhoneCode').val());        
          if(txtPhoneCode.length &gt; 0){
              txtPhoneCode = txtPhoneCode.replace(/\%/g, '-');
          }
  
          queryString = queryString + '&amp;txtEmail=' + txtEmail;
          queryString = queryString + '&amp;txtName=' + txtName;
          queryString = queryString + '&amp;txtPhone=' + txtPhone;
          queryString = queryString + '&amp;txtPhoneCode=' + txtPhoneCode;
  
          $.ajax({
              type: "GET",
              url: 'send.php',
              data: queryString ,
              success: function(msg) {
                  $('#response').html(msg);
              }
          });
  
          return false;
      });
  });
  </code></pre>
  
  <p>The PHP page:</p>
  
  <pre><code>&lt;?php
  if(isset($_GET['ajax']) &amp;&amp; ($_GET['ajax'] == 'true')){
      $name = trim($_GET['txtName']); // coming from input text
      $email = trim($_GET['txtEmail']); // coming from input text
      $phone = trim($_GET['txtPhone']); // coming from input text
      $phonecode = trim($_GET['txtPhoneCode']); // coming from a select
      if(strlen($name) == 0){
          echo 'Please enter your name';
      }
      elseif(strlen($email) == 0){
          echo 'Please enter your email';
      }
      elseif(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $email)){
          echo 'Please enter a valid email';
      }
      elseif(strlen($phonecode) == 0){
          echo 'Please select phone code';
      }
      elseif(strlen($phone) == 0){
          echo 'Please enter your phone';
      }
      elseif(!preg_match("/^[0-9]*$/i", $phone)){
          echo 'Please enter a valid phone';
      }
      else{
          require('config.php');
          // send to mysql db
          $email = stripslashes($email);
          $name = urldecode(str_replace('-', '%', $name));
          $phone = urldecode(str_replace('-', '%', $phone));
          $phonecode = urldecode(str_replace('-', '%', $phonecode));
          $dt = gmdate("Y-m-d H:i:s");
          $sql = "insert into subscribers(datecreated, name, email, phone, phonecode) values('$dt', '$name', '$email', '$phone', '$phonecode')";
          $result = mysql_query($sql) or die('Error: Failed to save subscription!');
          // redirect
          echo '&lt;script&gt;setTimeout(function(){ window.location = "thankyou.html#ty"; }, 0);&lt;/script&gt;';
      }
  }
  ?&gt;
  </code></pre>