loginService.islogged()
Above function return a string like "failed". However, when I try to run then function on it, it will return error of
上面的函数返回一个字符串,比如“failed”。但是,当我尝试运行它的函数时,它会返回错误。
TypeError: Cannot read property 'then' of undefined
and the cursor is indicate right after connected
and before .then
.
光标是在连接后和之前显示的。
Below is the full function:
以下是全部功能:
var connected=loginService.islogged();
alert(connected);
connected.then(function(msg){
alert("connected value is "+connected);
alert("msg.data value is "+msg.data);
if(!msg.data.account_session || loginService.islogged()=="failed")
$location.path('/login');
});
UPDATE
更新
Here is the islogged()
function
这是islog()函数。
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
return $checkSessionServer;
});
}
I am certain that the $checkSessionServer
will result in a "failed" string. Nothing more.
我确信$checkSessionServer将导致一个“失败”字符串。仅此而已。
2 个解决方案
#1
82
You need to return your promise to the calling function.
您需要将您的承诺返回给调用函数。
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
});
return $checkSessionServer; // <-- return your promise to the calling function
}
#2
0
TypeError: Cannot read property 'then' of undefined when calling a Django service using AngularJS.
TypeError:在使用AngularJS调用Django服务时不能读取未定义的属性。
If you are calling a Python service, the code will look like below:
如果您调用的是Python服务,那么代码如下所示:
this.updateTalentSupplier=function(supplierObj){
var promise = $http({
method: 'POST',
url: bbConfig.BWS+'updateTalentSupplier/',
data:supplierObj,
withCredentials: false,
contentType:'application/json',
dataType:'json'
});
return promise; //Promise is returned
}
We are using MongoDB as the database(I know it doesn't matter. But if someone is searching with MongoDB + Python (Django) + AngularJS the result should come.
我们使用MongoDB作为数据库(我知道这并不重要)。但是如果有人用MongoDB + Python (Django) + AngularJS来搜索,结果就会出现。
#1
82
You need to return your promise to the calling function.
您需要将您的承诺返回给调用函数。
islogged:function(){
var cUid=sessionService.get('uid');
alert("in loginServce, cuid is "+cUid);
var $checkSessionServer=$http.post('data/check_session.php?cUid='+cUid);
$checkSessionServer.then(function(){
alert("session check returned!");
console.log("checkSessionServer is "+$checkSessionServer);
});
return $checkSessionServer; // <-- return your promise to the calling function
}
#2
0
TypeError: Cannot read property 'then' of undefined when calling a Django service using AngularJS.
TypeError:在使用AngularJS调用Django服务时不能读取未定义的属性。
If you are calling a Python service, the code will look like below:
如果您调用的是Python服务,那么代码如下所示:
this.updateTalentSupplier=function(supplierObj){
var promise = $http({
method: 'POST',
url: bbConfig.BWS+'updateTalentSupplier/',
data:supplierObj,
withCredentials: false,
contentType:'application/json',
dataType:'json'
});
return promise; //Promise is returned
}
We are using MongoDB as the database(I know it doesn't matter. But if someone is searching with MongoDB + Python (Django) + AngularJS the result should come.
我们使用MongoDB作为数据库(我知道这并不重要)。但是如果有人用MongoDB + Python (Django) + AngularJS来搜索,结果就会出现。