title: Submit a Form Using Jquery Ajax
body: <p><a href="https://jsfiddle.net/pmdodbkp/2/" rel="nofollow noreferrer">Fiddle</a> And Code: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("form.signupform").submit(function(e) {
    var data = $(this).serialize();
    var url = $(this).attr("action");
    var form = $(this); // Add this line
    $.post(url, data, function(data) { 
      try {
          data = JSON.parse(data);
    $(.result).html(data.result + " Watchlist");
  
      } catch (e) {
          console.log("json encoding failed");
          return false;
      }
  });
    return false;
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;p class="result"&gt;&lt;/p&gt;
  &lt;form class="signupform" method="post" action="admin/signupinsert.php" onsubmit="this.onsubmit=function(){return false;}"&gt;
  
      &lt;input type="text" name="firstname" /&gt;
     &lt;input type="submit" value="Sign Up"/&gt;
  
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><code>admin/signupinsert.php</code> code: </p>
  
  <pre><code>// Insert into DB code in PHP
  
  $response = new \stdClass();
  $response-&gt;result = "".$result."";
  die(json_encode($response));
  </code></pre>
  
  <p>I am trying to submit this form using My Jquery Ajax Code. And the signupinsert.php file will return a value in $result variable. I am trying to print it inside <code>&lt;p class="result"&gt;&lt;/p&gt;</code></p>
  
  <p>But, the code re-directs users to signupinsert.php page.</p>
  
  <p>What's wrong?</p>