title: How can i submit a PHP form without redirect to action file? (send and get data with ajax)
body: <p>I load a form by click on a button with $("#btn").load("form.php") in index.php,
  I want to avoid redirect the page to action file after submit and add an item in the table which is under the form.</p>
  
  <p>my demo is on <a href="http://price.parag.website" rel="nofollow noreferrer">http://price.parag.website</a></p>
  
  <pre><code>&lt;?php include "../connection.php" ?&gt;
  
  &lt;h1&gt;Add CPU&lt;/h1&gt;
  
  &lt;form method="post" action="actions/cpu_action.php"&gt;
      &lt;label for="name"&gt;Name&lt;/label&gt;
      &lt;input type="text" name="cpu_name" /&gt;
      &lt;label for="price"&gt;Price&lt;/label&gt;
      &lt;input type="text" name="cpu_price" /&gt;
      &lt;input type="submit" value="Add" /&gt;
  &lt;/form&gt;
  &lt;?php
  
  $sql = "SELECT id, cpu_name, cpu_price FROM cpu";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      echo "&lt;table&gt;
      &lt;thead&gt;
      &lt;tr&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;CPU NAME&lt;/th&gt;
      &lt;th&gt;CPU PRICE&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;";
  
      while($row = $result-&gt;fetch_assoc())
      {
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;" . $row['id'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['cpu_name'] . "&lt;/td&gt;";
      echo "&lt;td&gt;" . $row['cpu_price'] . "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      }
      echo "&lt;/table&gt;";
  } else {
      echo "0 results";
  }
  </code></pre>