2014-04-23 133 views
1

我使用codeignitor。以下是我用於登錄表單驗證的jQuery代碼。表單提交後jquery重定向

  $("#login_form").validate({ 
       errorPlacement: function(error, element) { },// Disable error messages 
       debug:true, 
       rules: { 
        username: 
        { 
         required: true, 
         remote: 
         { 
          url: "http://localhost/my_site/index_page/validate_username_password", 
          type: "post", 
          data: { 
          password: function(){ return $("#password").val(); } //Password is sent alongside the username 
          } 
         } 
        }, 
       password:{required:true} 
       }, 
       highlight: function(username, errorClass) 
       { 
        $(username).fadeOut(function() 
        { 
         $(username).fadeIn(); 
        }); 
       }, 
       submitHandler: function(form) // CALLED ON SUCCESSFUL VALIDATION 
       { 
        window.location.replace='http://localhost/my_site/index_page'; 
       } 
      }); 

通過這個代碼,成功驗證後,我期待我的網頁重定向到

http://localhost/my_site/index_page 

,但事實並非如此。

我使用codeignitor。

+0

是submitHandler解僱?控制檯/網絡選項卡中的任何錯誤? –

+0

發送處理程序。我用alert()來檢查它。在cosole/Network選項卡中沒有錯誤。 –

+0

用什麼來代替:'window.location.replace('...');'?! –

回答

1

window.location.replace()是一個函數,用它作爲:

window.location.replace('http://localhost/my_site/index_page'); 
0

檢查this link,看到了提出的解決方案。

在跳到任何結論之前,確保submitHandler: function(form) {}確實被解僱。

0

試試這個:

使用

document.location='http://localhost/my_site/index_page'; 

代替

window.location.replace='http://localhost/my_site/index_page'; 
在你的代碼

...

+0

但這會在瀏覽器歷史記錄中添加新條目 –