title: Trying to stop form from redirecting after submit (return false & prevent.default are not working!)
body: <p>The problem I've been trying to solve for hours and hours now is following: I cannot stop the redirecting of #myform action after the data has been submitted succesfully to database. I've tried multiple methods but none seem to work. I'm in dire need of help!</p>
  
  <p>The code:</p>
  
  <p>Html(mainview.php):</p>
  
  <pre><code>    &lt;div id="submitAccordion"&gt;
  
      &lt;form id="myForm" action="userFiles.php" method="post"&gt;
          Name: &lt;input type="text" name="accordionName" /&gt;&lt;br /&gt;
          &lt;input id="sub" type="submit" name="go"  /&gt;
  
      &lt;/form&gt;
  
      &lt;span id="result"&gt;  &lt;/span&gt;
  
     &lt;/div&gt;
  </code></pre>
  
  <p>Javascript(mainview_script.js): </p>
  
  <pre><code> $("#sub").click(function () {
  
          var data = $("#myForm :input").serializeArray();
  
          $.post( $("#myForm").attr("action"),
          data, function(info) {
          $("#result").html(info); } )
          }); 
  
          $("#myForm").submit(function () {
  
          return false;
  
          }); 
  </code></pre>
  
  <p>php(userFiles.php):</p>
  
  <pre><code>session_start();
  require_once 'database.php';
  
  if ( isset($_SESSION['user_id']) ) {    
      $sql = "INSERT INTO useraccordion (id, h3) VALUES (:id, :accordion)";
      $stmt = $conn-&gt;prepare($sql);
      $stmt-&gt;bindParam(':id', $_SESSION['user_id']);
      $stmt-&gt;bindParam(':accordion', $_POST['accordionName']);
      if ( $stmt-&gt;execute() ) {
         echo "Succesfully inserted";
      } else {
          echo "Sorry, there was an error";
      }
  }
  </code></pre>
  
  <p>I have tried ajax method, prevent.default etc, but none work!</p>