2012-08-04 27 views
0

Okei ..我遇到一個小問題,我的ajax登錄。Cakephp 2.x Ajax帖子不能在第二次提交

當我第一次提交登錄表單時,它工作正常。

  • 輸入正確的用戶名/密碼=>登錄=>正常工作。
  • 如果鍵入錯誤的用戶名/密碼=>錯誤信息顯示=>(錯誤UNAME /單程)

但如果我嘗試重新輸入錯誤信息後顯示正確的用戶名和密碼,我無法提交再次的形式!?!

在螢火蟲它給了我一個「響應」與全頁面,形式我所在..

我需要重新加載頁面,以便能夠重新發布該登錄詳細信息。

我認爲這與安全組件有關,但禁用它是不可能的。

有什麼建議?

我的登錄信息的基礎知識。

var data = $("#LoginAjax").serialize(); 
$.ajax({ 
     type: "post", 
     url: "https://stackoverflow.com/users/ajax_login", 
     data: data, 
     dataType: "json", 
     success: function(data){ 
      if (data == 0) { 
       alert('wrong username/pass, try again!'); 
       //location.reload(); 
      } 
     } 
    }); 



public function ajax_login() { 
    $this->autoRender = false; 
    if ($this->request->is('ajax')) { 
     $this->request->data['User']['password'] = $this->Auth->password($this->request->data['User']['password']); 
     $user = $this->User->find('first', array('conditions' => array('username' => $this->request->data['User']['email'], 'password' => $this->request->data['User']['password']))); 
      if($user){ 
       echo 1;  
      } else { 
       echo 0; 
      } 
    } else { 
    $this->Session->setFlash('No Dice!', 'flash/alert'); 
    $this->redirect($this->Auth->logout()); 
    } 
    exit; 
} 

回答

0

嘗試在登錄視圖結束時添加echo $this->Js->writeBuffer();

爲什麼不使用CakePHP的JsHelper

相關問題