TypeError: Cannot read property 'then' of undefined

Ezeewei
loginService.islogged() 

Above function return a string like "failed". However, when I try to run then function on it, it will return error of

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

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.

TheSharpieOne

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
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: Cannot read property 'then' of undefined

From Dev

"TypeError: Cannot read property 'then' of undefined

From Dev

TypeError: Cannot read property 'image' of undefined

From Dev

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

From Dev

Uncaught TypeError: Cannot read property 'substr' of undefined

From Dev

TypeError: Cannot read property 'jquery' of undefined

From Dev

Angular TypeError cannot read property 'then' of undefined

From Dev

TypeError: Cannot read property 'valid' of undefined

From Dev

Uncaught TypeError: Cannot read property 'createRouteFromReactElement' of undefined

From Dev

Uncaught TypeError: Cannot read property 'ajax' of undefined

From Dev

Uncaught TypeError: Cannot read property 'call' of undefined

From Dev

TypeError: Cannot read property 'defaultPrevented' of undefined

From Dev

Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined

From Dev

Uncaught TypeError: Cannot read property 'addMethod' of undefined

From Dev

Uncaught TypeError: Cannot read property 'draw' of undefined

From Java

Uncaught TypeError: Cannot read property 'top' of undefined

From Dev

Getting TypeError: Cannot read property 'query' of undefined

From Dev

TypeError: Cannot read property 'post' of undefined in Nodejs

From Dev

Node: TypeError: Cannot read property 'on' of undefined

From Dev

Uncaught TypeError: Cannot read property 'parentNode' of undefined

From Dev

TypeError: Cannot read property 'username' of undefined?

From Java

Uncaught TypeError: Cannot read property 'linear' of undefined

From Dev

TypeError: Cannot read property 'childNodes' of undefined angular

From Dev

Uncaught TypeError: Cannot read property 'document' of undefined

From Dev

typeerror cannot read property 'data' of undefined

From Java

ERROR in TypeError: Cannot read property 'flags' of undefined

From Java

Redux TypeError: Cannot read property 'apply' of undefined

From Java

TypeError: Cannot read property 'wanted' of undefined:

From Java

TypeError: Cannot read property 'webpackJsonp' of undefined

Related Related

  1. 1

    TypeError: Cannot read property 'then' of undefined

  2. 2

    "TypeError: Cannot read property 'then' of undefined

  3. 3

    TypeError: Cannot read property 'image' of undefined

  4. 4

    Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

  5. 5

    Uncaught TypeError: Cannot read property 'substr' of undefined

  6. 6

    TypeError: Cannot read property 'jquery' of undefined

  7. 7

    Angular TypeError cannot read property 'then' of undefined

  8. 8

    TypeError: Cannot read property 'valid' of undefined

  9. 9

    Uncaught TypeError: Cannot read property 'createRouteFromReactElement' of undefined

  10. 10

    Uncaught TypeError: Cannot read property 'ajax' of undefined

  11. 11

    Uncaught TypeError: Cannot read property 'call' of undefined

  12. 12

    TypeError: Cannot read property 'defaultPrevented' of undefined

  13. 13

    Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined

  14. 14

    Uncaught TypeError: Cannot read property 'addMethod' of undefined

  15. 15

    Uncaught TypeError: Cannot read property 'draw' of undefined

  16. 16

    Uncaught TypeError: Cannot read property 'top' of undefined

  17. 17

    Getting TypeError: Cannot read property 'query' of undefined

  18. 18

    TypeError: Cannot read property 'post' of undefined in Nodejs

  19. 19

    Node: TypeError: Cannot read property 'on' of undefined

  20. 20

    Uncaught TypeError: Cannot read property 'parentNode' of undefined

  21. 21

    TypeError: Cannot read property 'username' of undefined?

  22. 22

    Uncaught TypeError: Cannot read property 'linear' of undefined

  23. 23

    TypeError: Cannot read property 'childNodes' of undefined angular

  24. 24

    Uncaught TypeError: Cannot read property 'document' of undefined

  25. 25

    typeerror cannot read property 'data' of undefined

  26. 26

    ERROR in TypeError: Cannot read property 'flags' of undefined

  27. 27

    Redux TypeError: Cannot read property 'apply' of undefined

  28. 28

    TypeError: Cannot read property 'wanted' of undefined:

  29. 29

    TypeError: Cannot read property 'webpackJsonp' of undefined

HotTag

Archive