1. /* AJAX CODE */
  2.  
  3. $.ajax({
  4. type: "POST",
  5. data: {'data':{
  6. 'User':{
  7. 'email': email,
  8. 'password': password
  9. }
  10. }},
  11. url: baseUrl+"/users/login",
  12. success: function(result) {
  13. console.log(result);
  14. }
  15. });
  16.  
  17. /* users_controller.php */
  18.  
  19. function login() {
  20. if($this->RequestHandler->isAjax() == true) {
  21. if ($this->Session->check('Auth.User')) {
  22. echo "true";
  23. } else {
  24. echo json_encode($this->data);
  25. }
  26. $this->render(null,'ajax');
  27. exit;
  28. }
  29.  
  30. function beforeFilter() {
  31. parent::beforeFilter();
  32. $this->Auth->fields = array('username' => 'email', 'password' => 'password');
  33. }
  34.