angularjs - Javascript null checking not working as expected -


i'm using angularjs framework , connect webservice fetch json data. have following code:

$login.onlinelogin($scope.credentials).     success(function (data, status, headers, config) {          if (data !== null ) {             console.log('successful login!');             console.log('returned data: ' + data);         } else {             console.log('failed login...');         }      }).     error(function (data, status, headers, config) {         console.log('http error...');     }); 

now, when http call comes status still 200:ok object returns null, in case user provided wrong user credentials example. i'm expecting happen in case if object not null, it'll print out 'successful login!' , print out object.

however, what's happening use fake credentials, webservice returns null. still 'successful login!' gets printed, , after prints 'returned data: null'... doesn't make sense. if data null, should never have ended in code block?

if you're not sure type of variable use.

console.log(typeof variablename) 

in case, problem can fixed using

if (data != 'null') { ... 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -