Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6827651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:17:25+00:00 2026-05-26T22:17:25+00:00

I am trying to create an ajax login script but have hit a wall.

  • 0

I am trying to create an ajax login script but have hit a wall. I hav built one before but now using the cakephp framwework.
I’m not really sure ho to go about this. At the moment I have a login function in the controller,

public function login()
{
    if($this->request->is('post')) {
        if($this->Auth->login()) {
            $this->Session->setFlash('Login Passed');
        } else {
            $this->Session->setFlash('Login Failed');
        }
    }
}

Do i then use ajax to send values to this from the form? These lines are from my old (non-cakephp) system,

xmlhttp.open("POST","http://www.site.com/login/",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("AttemptLogin=true&AccountEmail="+ userMail +"&AccountPassword=" + userPass);

Should i modify them in any way? Also, how do i handle any validations and login attempts with errorsetc.

Sorry about the question being quite open ended and long but i don’t know where to go,I have looked for tutorials but can’t find any.

Many Thanks
Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:17:26+00:00Added an answer on May 26, 2026 at 10:17 pm

    You can use javascript helper from cake and have one template that converts
    the response to the json format, in the controller just include the helper:

    var $helpers = array('Javascript');
    var $components = array('RequestHandler');
    
    //the template ie "/views/templates/ajax.ctp"
    echo $javascript->object(isset($response) ? $response : array());
    

    So yo can set you function like:

    public function login()
    {
      if($this->RequestHandler->isPost()) {
         if($this->Auth->login()) {
            $response('success'=>true);
         } else {
            $response('success'=>false);
         }
       $this->set('response', $response);
       $this->render(null, 'ajax');
    }
    

    And the javascript i recommend jQuery

    $.ajax({url:"/controller/login",type:"POST", data:$('#formLogin').serialize(), dataType:"json", success:responseLogin, context:this});
    
     function responseLogin(response)
     {
         //here is the object returned by cakephp
         if(!response.success)
            //do something the user don't login
         else
           //do something the user pass the login
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an example where I am trying to create an AJAX login using
I am trying to create a simple log in system that uses ajax but
I'm trying to create a AJAX push implementation in PHP using a Comet long-polling
I am trying to do a simple application using Ajax and servlet. But when
I'm trying to create an Ajax enabled webform, and have created a simple page.
I'm trying to create a simple AJAX & web service test (using C# .Net
I'm trying to create a simple login system that will have the forms and
I have using colobox which is a jquery modal window to create a login/regiestration
I'm trying to create a simple ajax load test script that dynamically creates divs,
Im trying to create an ajax (post) event that will populate a table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.