Model Page (My_model.php)
<?php
class My_model extends CI_Model{
function check(){
$v=$this->input->post('username');
$query=$this->db->query("SELECT email FROM fi_login WHERE email='$v'");
if($query->num_rows()>0){
return TRUE;
}else{
return FALSE;
}
}
}
?>
View Page(ajaxlog_view.php)
<div><input id="email" name="email" type="text" value="" /><input></div>
<script src="<?php echo base_url();?>assets/js/jquery.min.js"></script>
<script>
$(function(){
$('#email').blur(function(){
v=$(this).val();
$.ajax({
url: '<?php echo base_url() ?>ajaxlog/email_check',
type: 'post',
data: 'username='+v,
success : function(r){
alert(r);
}
})
})
});
</script>
Controller Page(ajaxlog.php)
<?php
class Ajaxlog extends CI_Controller{
function index(){
$this->load->view('ajaxlog_view');
}
function email_check(){
$this->input->post();
$this->load->model('My_model');
if($this->My_model->check())
echo "Username not available";
else
echo "available";
}
}
<?php
class My_model extends CI_Model{
function check(){
$v=$this->input->post('username');
$query=$this->db->query("SELECT email FROM fi_login WHERE email='$v'");
if($query->num_rows()>0){
return TRUE;
}else{
return FALSE;
}
}
}
?>
View Page(ajaxlog_view.php)
<div><input id="email" name="email" type="text" value="" /><input></div>
<script src="<?php echo base_url();?>assets/js/jquery.min.js"></script>
<script>
$(function(){
$('#email').blur(function(){
v=$(this).val();
$.ajax({
url: '<?php echo base_url() ?>ajaxlog/email_check',
type: 'post',
data: 'username='+v,
success : function(r){
alert(r);
}
})
})
});
</script>
Controller Page(ajaxlog.php)
<?php
class Ajaxlog extends CI_Controller{
function index(){
$this->load->view('ajaxlog_view');
}
function email_check(){
$this->input->post();
$this->load->model('My_model');
if($this->My_model->check())
echo "Username not available";
else
echo "available";
}
}
0 comments:
Post a Comment