所以我使用Jquery post包装器从我的页面运行脚本,并在chrome调试器中发生以下情况: -
1) if the username is taken i'm getting `"taken"`
2) else it echo's nothing.
但是,我无法进入警告('我在这里'); 一行似乎if(data=="taken")
语句从未运行或始终评估为 false ,情况并非如此。我做错了什么?
var flag;
$.post('welcome/check_username',{childname: $('#name').val()}, function(data){
if(data=="taken")
{
alert('im here');
return flag = true;
//tell user that the username already exists
}else{
return flag = false;
//username doesn't exist, do what you need to do
}
});
if ($this->Form_builder->check_unique_username($username, $childname))
{
echo "taken";
}
答案 0 :(得分:1)
试试这个:
var flag;
var result = $.post('welcome/check_username',{childname: $('#name').val()});
result.done(function( data )
{
if(data=="taken")
{
alert('im here');
return flag = true;
//tell user that the username already exists
}else{
return flag = false;
//username doesn't exist, do what you need to do
}
});
答案 1 :(得分:1)
if(data.trim()=="taken")
答案 2 :(得分:1)
查看代码,以下是我要检查的部分:
在PHP端,检查函数是否正确地在$ username和$ password中获取正确的值。您可以通过修改PHP文件来执行此操作:
if ($this->Form_builder->check_unique_username($username, $childname)) { echo "taken"; } else { echo $username." and ".$childname." is not taken"; }