Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  23] [ 4]  / answers: 1 / hits: 5819  / 10 Years ago, wed, december 31, 2014, 12:00:00

this is my controller function



    public function verifyUser()    
{
$userName = $_POST['email'];
$userPassword = $_POST['password'];
$var=array('email'=>$userName,'password'=>$userPassword);
$check=$this->mymodel->login_validation($var);


//$status = array(STATUS=>false);
if(count($check))
{
redirect('main/valid_login');

}
else
{
echo <div style='border:1px solid red;font-size: 11px;margin:0 auto !important;'>Could't Authorize to the system! Try again with valid credentials.</div> ;
}
}


this is my ajax function



    <script>
function makeAjaxCall(){
$.ajax({
type: post,
url: <?php echo site_url('main/verifyUser');?>,
cache: false,
data: $('#userForm').serialize(),
success:function(msg)
{
$('#show_id').html(msg);
}
});
}
</script>


this is my form



 <form name=userForm id=userForm action=>
<div id=show_id></div>
<fieldset>

<p><label for=email>E-mail address</label></p>
<p><input type=email id=email placeholder=enter your email id name=email></p> <!-- JS because of IE support; better: [email protected] -->

<p><label for=password>Password</label></p>
<p><input type=password id=password placeholder=******* name=password style=width: 328px;></p> <!-- JS because of IE support; better: placeholder=password -->

<p><input type=button value=Sign In onclick=javascript:makeAjaxCall();></p>

</fieldset>

</form>


everything is working fine,but when i entered the valid username and password,its not redirecting to any page,so please help me on this


More From » php

 Answers
4

Send JSON data to ajax as response and handle it according to need.

Contorller:



public function verifyUser()  {

$userName = $_POST['email'];
$userPassword = $_POST['password'];
$var=array('email'=>$userName,'password'=>$userPassword);
$check=$this->mymodel->login_validation($var);


//$status = array(STATUS=>false);
if(count($check)) {
$this->output
->set_content_type(application/json)
->set_output(json_encode(array('status'=>true, 'redirect'=>base_url('main/valid_login') )));
}
else {
$this->output
->set_content_type(application/json)
->set_output(json_encode(array('status'=>false, 'error'=>'Could't Authorize to the system! Try again with valid credentials.')));
}
}


Handle JSON data with ajax.



$.ajax({
type: post,
url: <?php echo site_url('main/verifyUser');?>,
cache: false,
data: $('#userForm').serialize(),
dataType: 'json',
success:function(response) {
if( response.status === true )
document.location.href = response.redirect;
else
$('#show_id').html(<div style='border:1px solid red;font-size: 11px;margin:0 auto !important;'>+response.error+</div>);
}
});

[#40319] Tuesday, December 30, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ignacio

Total Points: 467
Total Questions: 128
Total Answers: 79

Location: Luxembourg
Member since Tue, Mar 14, 2023
1 Year ago
;