title: Submitting basic form data with AJAX to PHP web service
body: <p>I'm trying to submit some form data using jQuery / Ajax to a PHP web service (php file) and simply echo the results, for now.</p>
  
  <p>Here is my index.html file</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHP web service &amp;amp; AJAX&lt;/title&gt;
  &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
  &lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1&gt;Hello! Is it me you're looking for?&lt;/h1&gt;
  
      &lt;form id="submit"&gt;
          &lt;label&gt;Name&lt;/label&gt;
          &lt;input id="name" type="text" name="name" /&gt;
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input id="email" type="email" name="email" /&gt;
          &lt;input class="submit" type="submit" value="Submit details" /&gt;
      &lt;/form&gt;
  
      &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              $(".submit").click(function(e) {
                  e.preventDefault();
  
                  // BUILD DATA STRING
                  var name = $("#name").val();
                  var email = $("#email").val();
                  var dataString = "subName=" + name + "&amp;subEmail=" + email;
  
                  $.ajax({
                      type: 'POST',
                      url: 'results.php',
                      data: dataString,
                      success: function() {
                          window.location.href = "results.php";
                      }
                  });
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>And the PHP (results.php) file</p>
  
  <pre><code>&lt;?php
      echo $_POST['subName'] . "&lt;br /&gt;" . $_POST['subEmail'];
  ?&gt;
  </code></pre>
  
  <p>Having no luck so far, can anyone help me out? I've tried <a href="https://stackoverflow.com/questions/16616250/form-submit-with-ajax-passing-form-data-to-php-without-page-refresh">this tutorial</a> and <a href="https://stackoverflow.com/questions/19736272/passing-form-data-and-file-to-php-using-ajax">this one</a> as well but they haven't helped.</p>