我正在尝试使用jQuery + Ajax Codeigniter问题检查电子邮件的可用性我正面临我的加载器图像未加载哪些应该在可用性检查过程中加载 我的js文件代码
$(document) . ready(function(){
$("#email_address").change(function(){
var email = $("#email_address").val();
$("#availability_email").html("<img src='<?php echo base_url();?>Images/loader.gif' align='absmiddle'> ...");
$.ajax({ //starting ajax request
type: "POST",
url: "user/check_email_registered",
data: "email_address="+ email,
success: function(emailtest){
if(emailtest==0){
$("#availability_email"). html("<img src='<?php echo base_url();?>Images/notavailable.png'>Email Not Registered");
}else{
$("#availability_email"). html("<img src='<?php echo base_url();?>Images/available.png'>Yes! you can send reset link on this address!");
}
}
});
});
});
我的视图文件registration_view.php代码片段和当前我在我的视图文件的head部分中包含了js文件
<label for="email_address">Your Email:</label>
<?php echo form_error('email_address','<div class="error">', '</div>');?>
<input type="text" id="email_address" name="email_address" value="<?php echo set_value('email_address'); ?>" /><span id="availability_email"></span>
</p>
我的控制器部分
public function check_email_registered()
{
$get_result = $this->user_model->check_email_registered();
if(!$get_result)
{
echo 'Email Already in user';
} else {
echo 'Email available';
}
我的模特部分
public function check_email_registered()
{
$email = $this->input->post('email_address');
$check_for_email = "SELECT * FROM SYSTEM_USERS WHERE Email= $email AND Activation 0";
$result = $this->db->query($check_for_email);
if($result->num_rows() > 0)
{
return FALSE;
}else
return TRUE;
}
答案 0 :(得分:0)
首先,我发现您的javascript评估存在问题。
success: function(emailtest){
if(emailtest==0){
$("#availability_email"). html("<img src='<?php echo base_url();?>Images/notavailable.png'>Email Not Registered");
}else{
$("#availability_email"). html("<img src='<?php echo base_url();?>Images/available.png'>Yes! you can send reset link on this address!");
}
}
和
check_email_registered()
总是返回一个字符串,所以(emailtest == 0)在每种情况下都为FALSE
其次查询错误:
$check_for_email = "SELECT * FROM SYSTEM_USERS WHERE Email= $email AND Activation 0";
激活0(必须)激活= 0
如果问题仍然存在,请提供有关Chrome或Firefox错误使用检查器的详细信息!
<强>更新强> 另一个问题
数据:“email_address =”+电子邮件,
必须是json对象
数据:{“email_address”:email}