Welcome Guest, Not a member yet? Register   Sign In
Jquery Database Query and handling output.
#4

[eluser]pickupman[/eluser]
First just make sure everything is working with javascript for degradation purposes. When using .ajax() return something from your controller in json, and on the success: callback process the json.

Code:
$('form#frmRecover').submit(function() {
    $.ajax({
        url: $(this).attr('action'),
        type: 'POST',
        data: $(this).serialize,
        success: function(data){
            if(data.response = 'true'){
               $(".response-msg").empty().append(data.message);                          
            }
        }
    });
    return false;
});

//In controller/action method

//Check if page is coming via AJAX
if($this->input->is_ajax_request()){
  
   $data['response'] = 'false'; //set default json response

   //Process login
   $user = $this->usermodel->login( $this->input->post('email'), $this->input->post('password') ); //run your login query
   if($user){
      $this->session->set_userdata('id', $user->id);
      $this->session->set_userdata('logged_in', TRUE);
      $data['response'] = 'true'; //for json
      $data['message']  = 'Welcome back ' . $user->first_name;
   }
   return json_encode($data); //return JSON back to jQuery
}


Messages In This Thread
Jquery Database Query and handling output. - by El Forum - 08-13-2011, 02:27 PM
Jquery Database Query and handling output. - by El Forum - 08-13-2011, 02:30 PM
Jquery Database Query and handling output. - by El Forum - 08-13-2011, 03:47 PM
Jquery Database Query and handling output. - by El Forum - 08-13-2011, 05:45 PM
Jquery Database Query and handling output. - by El Forum - 08-13-2011, 07:47 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 02:09 AM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 03:49 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 04:40 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 05:04 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 06:46 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 08:18 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 08:29 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 08:32 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 09:24 PM
Jquery Database Query and handling output. - by El Forum - 08-14-2011, 10:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB