我正在尝试使用PHP Codigniter,Ajax和Jquery在应用程序中实现实时电子邮件复制检查。但我没有取得任何成功的结果。
Jquery的
<script type="text/javascript">
$(document).ready(function()
{
$("#email").keyup(function()
{
if($("#email").val().length >= 4)
{
$.ajax(
{
type: "POST",
url: "<?php echo site_url('stthomas/check_user');?>",
data: "email="+$("#email").val(),
success: function(msg)
{
if(msg=="true")
{
$("#usr_verify").css({ "background-image": "url('<?php echo base_url();?>images/yes.png')" });
}
else
{
$("#usr_verify").css({ "background-image": "url('<?php echo base_url();?>images/no.png')" });
}
}
});
}
else
{
$("#usr_verify").css({ "background-image": "none" });
}
});
});
</script>
我的表格如下
<div class="form-group formgp">
<label class="col-md-4" for="Inputemail">Email :</label>
<div class="col-md-8" >
<input type="text" name="email" class="form-control" id="email" value="<?php echo set_value('email'); ?>" placeholder="Email"> <span id="usr_verify" class="verify"></span>
</div>
</div>
控制器:
public function check_user()
{
$usr=$this->input->post('email');
$result=$this->stthomas_model->check_user_exist($usr);
if($result)
{
echo "false";
}
else{
echo "true";
}
}
型号:
public function check_user_exist($usr)
{
$this->db->where("email",$usr);
$query=$this->db->get("email");
if($query->num_rows()>0)
{
return true;
}
else
{
return false;
}
}
答案 0 :(得分:0)
要猜出问题并不容易,但最好检查jquery ajax错误细节。您刚刚在代码中设置了流程的成功部分:
success: function(msg){
如果ajax出错,请查看您的错误:
success: function(msg){
// success code
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}