Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other CakePHP Ajax Login

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #35292
    ChrisBull
    Member

    Hi, firstly this is a long question but I hope somone can help me.
    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,

    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');
    }
    }

    My Javascript Code,

    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');
    }

    I have over the course of the weeken changed the code dramaticaly and this is the end result which doesn’t work – but i have no idea where i’m meant to be heading with this I might be completely wrong!
    Can someone please help me?

    Many thanks for your time.
    Chris

Viewing 1 post (of 1 total)
  • The forum ‘Other’ is closed to new topics and replies.