Welcome Guest, Not a member yet? Register   Sign In
Modal Form of Jquery with Codeigniter always return to false
#1

[eluser]nOsCiRe[/eluser]

in my js script
function usernameexist()
{

$.ajax({
type: "POST",
url: "<?Php echo base_url();?>home/check_user",
data: "name="+$("#new-username").val(),
success: function(msg){
if(msg=="true")
{
alert('true')
}
else
{

alert('false')
}
}
});
}

IN MY CONTROLLER
function check_user()
{

$this->load->model('user');
$usr=$this->input->post('name');

$result=$this->user->check_user_exist($usr);
if($result)
{
echo "true";
}
else
{
echo "false";
}
}
IN MY MODEL


function check_user_exist($usr)
{

$query=$this->db->get_where('ad_users',array('username'=>$usr));
if($query->num_rows()>0)
{
return true;
}
else
{
return false;
}
}
#2

[eluser]InsiteFX[/eluser]
It would help if next time you post that you wrap your code in code tags!

#3

[eluser]aquary[/eluser]
Apart from the above, try to check also if your query return a valid result.
#4

[eluser]CroNiX[/eluser]
If your js is in a standalone .js file, you can't use php in it unless you configure apache to parse js files as if they were php files, so your base_url() probably isn't working in there. Check firebug/console and see where the request is actually being sent to.
#5

[eluser]Make Code& Love Code[/eluser]
Check whether your values are posting to Controller or not in Firebug Console. If not then you have to check your Ajax post and Base url first. Have a look .. This may help you

Code:
var email_address = $("#email").val();
var password = $("#password").val();
var postData = {
  'email' : email_address,
  'password' : password
};

$.ajax({
     type: "POST",
     url: "some.php",
     data: postData , //assign the var here
     success: function(msg){
        alert( "Data Saved: " + msg );
     }
});






Theme © iAndrew 2016 - Forum software by © MyBB