I'm trying to turn my login form into an ajax one but am having difficulty achieving this using cakephp (I have created ajax login forms before just not through cake). I also can't find any tutorials online everywhere and so after a full weekend of struggling and to no avail I seek someone on heres help.
OK, onto the code.
Here is my controller code,
Code: Select all
public function login()
{
if(!empty($this->data)) {
if($this->RequestHandler->isAjax()) {
if($this->Auth->login()) {
$response = array('success' => TRUE);
} else {
$response = array('success' => FALSE);
}
}
$this->set('response', $response);
$this->render('ajaxReturn', 'ajax');
}
}Code: Select all
function sendToPHP() {
$.ajax({url:"/accounts/login",type:"POST", data:$('#loginForm').serialize(), dataType:"json", success:responseLogin, context:this});
}
function responseLogin(response)
{
if(!response.success)
alert('hello');
else
alert('hello2');
}Can someone please help me?
Many thanks for your time.
Chris