我正在尝试实现 Facebook 登录程序,但它不起作用。我有一个 POST 到 AJAX,它似乎错误地解释了返回的 TRUE。尽管我已经将日志放在整个过程中以跟踪逻辑流......它似乎并没有像我预期的那样流动。你能看出问题吗?
这是我发布到 AJAX 的 .js
function initUserFbConnect(response){
console.log("initUserFacebookConnect");
// checking if the user is in the DB or first visit
$.post('../ajax/checkFbMember', { facebookId: response.id },
function(data){
if(data){
console.log("trying to set login time");
$.post('../ajax/setLoginTime', { facebookId:response.id },
function(data2){
if(data2 == true){
console.log("Login time logged");
}else{
console.log("problem logging time");
}
}
);
}else{
console.log("returned false from AJAX post");
console.log(data);
console.log("you are NOT a FB member");
}
}
);
}
这里是 ../ajax/checkFbMember
public function checkFbMember()
{
$facebookId = $this->input->post('facebookId');
ChromePhp::log("checking checkFBmember " . $facebookId );
$this->load->model('Member_model');
if( $this->Member_model->mCheckFbMember( $facebookId )){
ChromePhp::log('FB id found in system');
return TRUE;
}else{
ChromePhp::log('FB id NOT found in system');
return FALSE;
}
}
这是我的 Member_model
public function mCheckFbMember( $facebookId )
{
ChromePhp::log('Inside model and checking');
$_query = $this->db->query( "SELECT users.id FROM users WHERE users.facebookID=$facebookId" );
if ( $_query->num_rows() > 0 ){ // user is found
ChromePhp::log('Inside model and FOUND member');
return TRUE;
}else{ // means first visit
ChromePhp::log('Inside model FAIL');
return FALSE;
}
}
但这就是我正在记录的内容..顺序很奇怪
initUserFacebookConnect
returned false from AJAX post // << this seems to come too early!
// console.log(data) doesn't log anything .. why?
you are NOT a FB member
checking checkFBmember 657322189
Inside model and checking
Inside model and FOUND member
FB id found in system
所以我要发布到 ajax .. 我正在点击我的模型并将 TRUE 返回到我的控制器,控制器将 TRUE 返回到 initUserFbConnect .. 但不知何故那个 POST 方法接收 FALSE?不仅如此..它会直接跳过并在我的任何其他方法触发 之前向我显示“返回错误” ?
我很困惑为什么我要返回 FALSE,因为我在数据库中找到了该成员。但我也对我的日志记录触发的顺序感到困惑。我希望 initUserFbConnect 中的 IF 语句在其他所有内容返回后解决。但它似乎在跳枪。它必须首先通过 PHP 和 DB 检查才能知道它已收到 TRUE/FALSE,对吗?
谁能解释发生了什么?