[eluser]chantheoun[/eluser]
Now I am facing a problem with post form value through jquery .serialize(). when past form value to jquery function, it can get them all as method Post. But when using .serialize() to send form value to controller, the controller can't get that value. Here is my code:
in view:
<form id="loginForm" name="loginForm" method="post">
Email: <input type="text" class="contactStyle required email" id="email" name="email"/>
Password:<input type="password" class="contactStyle required" id="password" name="password"/>
</form>
<a href='#' class="loginBut">Login</a>
in jquery:
login = function(){
.post(base_url + "elements/ajax_login", $("#loginForm").serialize(),
function(data){
if(data.success == 'success'){
top.location = top.location;
}else if(data.success == 'admin'){
top.location = base_url + "admin";
}else if(data.success == 'failed'){
alert('Incorrect login');
//ADD POPUP
$('#warn').hide().html('Your email / password combination is not correct.').show('slow');
}else{
alert("An error has occured please try refreshing the page.")
}
},'json');
}
in controller:
function ajax_login() {
$email = $this->input->post('email');
$result = array();
if ($this->ion_auth->login($email, $this->input->post('password'), 0)) { //if the login is successful
//if its an admin send them to the dashboard
if ($this->ion_auth->is_admin()) {
$result['success'] = 'admin';
} else {
$result['success'] = 'success';
}
} else { //if the login was un-successful
$result['success'] = 'failed';
}
echo json_encode($result);
}
I got the error that first step that passing value from view to jquery is Method Post but when passing value from jquery to controller is Method Get.
If anyone has solution or idea, please help.
Regards,
Chantheoun