[eluser]mast3rpyr0[/eluser]
Hey guys, this one has been stumping me since my last post here.. I can't manage to receive any data from my ajax call to log a user in. It is successully creating the session, so the php does execute, but nothing is in the 'data' variable when it returns. It could just be my lack of jquery know how but I'm completely stumped, I feel like I have tried everything.
If instead of returning data I do a redirect, my data variable will have the code of the page it would have redirected to. Using returns, echos, or prints however with a normal string or json data, do not return any data.
Heres my code:
php
Code:
if($this->form_validation->run() == false)
{
return json_encode(array('message' => validation_errors()));
}
else
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('account_model');
if($this->account_model->validate_credentials($username, $password))
{
$sessiondata = array(
'username' => $username,
'loggedin' => true
);
$this->session->set_userdata($sessiondata);
return json_encode(array('message' => 'success'));
}
else
{
return json_encode(array('message' => 'Invalid Username or Password'));
}
}
ajax call
Code:
$("#loginform").submit(function(event){
event.preventDefault();
$.post($(this).attr('action'), $(this).serialize(), function(data){
alert("Data: " + data);
});
});