2016-02-20 70 views
2

我想讓我的表單停留在使用jquery的同一頁上。我正在使用名爲#clientUpdate-form的表單將其輸入到update.php。我曾試圖消除window.location.href並試圖改變它window.location.href =「edit_form.php edit_id =?」 + edit_id但形式上總是恢復到index.php的提交表格並留在同一頁面上?

全碼:

/* 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 */ 
+2

可能重複[如何防止表單被提交?](http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted) –

回答

1

您需要防止表單提交的默認事件。

$(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 
});