2

I'm trying to make my form stay on the same page using jquery. I'm using a form named #clientUpdate-form that posts it's input to update.php. I have tried removing the window.location.href and tried changing it to window.location.href="edit_form.php?edit_id="+edit_id but the form always reverts back to index.php

Full Code:

 /* Update Record  */
 $(document).on('submit', '#clientUpdate-form', function() {
    $.post("update.php", $(this).serialize()).done(function(data) {
        $("#dis").fadeOut();
        $("#dis").fadeIn('slow', function() {
            $("#dis").html('<div class="alert alert-info">' + data + '</div>');
            $("#clientUpdate-form")[0].reset();
            $("body").fadeOut('slow', function() {
                $("body").fadeOut('slow');
                window.location.href = "index.php";
            });
        });
    });
    return false;
 });
 /* Update Record  */
Satpal
  • 132,252
  • 13
  • 159
  • 168
GreyTek
  • 89
  • 1
  • 1
  • 6
  • 2
    Possible duplicate of [How to prevent form from being submitted?](http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted) – Michał Perłakowski Feb 20 '16 at 02:54

1 Answers1

2

you need to prevent the default event of form submit.

$(document).on('submit', '#clientUpdate-form', function(e) { // note the e, thats the event 
   e.preventDefault(); // this stops the default event of the form
   // then your stuff goes here
});
Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59