2011-08-30 51 views
2

叫的時候我也弄不清是什麼在這裏,但不知何故發生了我的頁面被刷新/當我打電話$.post在驗證插件的submitHandler內部重定向。後端只是簡單地返回一個HTTP狀態代碼200

這裏是我的代碼:

$('form[name=comment]').validate({ 
    submitHandler: function(form) { 
     $('#postComment').attr('disabled', 'disabled'); 
     $.post('/blog/comments/create/', form.serialize(), function() { 
      prependComment(form); 
      return false; 
     }).error(function() { 
      alert('There was an issue when submitting this comment.'); 
     }).complete(function() { 
      $('#postComment').removeAttribute('disabled'); 
     }); 
     return false; 
    } 
}); 

下面是HTML

<form action="/blog/comments/create/" name="comment" method="post"> 

    <input type="hidden" name="post" value="1"/> 
    <ul> 
     <li>      
      <input type="text" name="name" value="Your name" class="required"/> 
     </li> 
     <li> 
      <textarea name="message" rows="10" cols="55" class="required"></textarea> 
     </li> 
     <li> 
      <button type="submit" id='postComment' class="primary">Post comment</button> 
     </li> 
    </ul> 
</form> 
+1

附註 - 尼斯的頭像。 –

+0

您是否在'submitHandler'中嘗試過'返回false;'? –

+0

我做到了。我甚至在submitHandler中設置了一個斷點。當$ .post被調用時,它將頁面重定向到表單的動作。此外,你的頭像也同樣吸引人。 :) – intargc

回答