title: AJAX not preventing redirection to PHP page
body: <p>With the help of AJAX, I've been trying to prevent the automatic redirection to a blank PHP page after submitting a form, but I'm not managing. The data submitted to the form is being entered into the MySQL table, but upon clicking submit, I'm always redirected to the blank <code>insert.php</code> page.
  Here is the HTML form:</p>
  <pre><code>            &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;form class = &quot;ajax&quot; action = &quot;insert.php&quot; method=&quot;POST&quot;&gt;
                      &lt;td&gt;&lt;input type=&quot;text&quot; class = &quot;inputs&quot; name = &quot;dcs&quot; id = &quot;dcs&quot;/&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type=&quot;text&quot; class = &quot;inputs&quot; name = &quot;qty&quot; id = &quot;qty&quot;/&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type=&quot;text&quot; class = &quot;inputs&quot; name = &quot;rate&quot; id = &quot;avg&quot;/&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;div style = &quot;position: relative;&quot;&gt;&lt;input type=&quot;submit&quot; onclick=&quot;add_new_entry();&quot; id = &quot;submit&quot;/&gt;&lt;/div&gt;&lt;/td&gt;
                  &lt;/form&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;tr&gt;  
  </code></pre>
  <p>Here is the jQuery function:</p>
  <pre><code>        $(document).ready(function() {
          
              $('form.ajax').submit(function(event) {
                  event.preventDefault();
                  var that = $(this),
                      url = that.attr('action'),
                      type = that.attr('method'),
                      data = {};
  
                  that.find('[name]').each(function(index, value) {
                      var that = $(this),
                          name = that.attr('name'),
                          value = that.val();
  
                      data[name] = value;
                  });
  
                  $.ajax({
                      url: url,
                      type: type,
                      data: data,
                      success = function(response) {
                          alert(response);
                      }
                  });
                  return false;
  
              });
  
          });
  </code></pre>
  <p>Here is <code>insert.php</code>:</p>
  <pre><code>&lt;?php
  
  include &quot;db_connect.php&quot;;
  
  $code = 4;
  $dcs =  mysqli_real_escape_string($conn, $_POST['dcs']);
  $qty = mysqli_real_escape_string($conn, $_POST['qty']);
  $rate =  mysqli_real_escape_string($conn, $_POST['rate']);
  $total = $qty * $rate;
  
  $sql = &quot;INSERT INTO entries  VALUES ('$code',
              '$dcs','$qty','$rate','$total');&quot;;
  
  // $conn is the connection
  mysqli_query($conn, $sql)
  
  mysqli_close($conn);
  
  ?&gt;
  </code></pre>
  <p>Please let me know of the changes that I should make so that I'm not redirected to the PHP page after submitting the form.</p>
  <p>Let me know if I should provide any other code snippets.</p>
  <p>Thanks a lot.</p>