doubts with if else in java script

1

I'm using AngularJs and I have this method

$scope.login = function (email, usuario, senha) {
    $http.post("/Login/login", { email: email, usuario: usuario, senha: senha })
    .success(function (data) {
        debugger;

        if (data == "Empresa nao encontrada.") {
            UIkit.modal.alert(data, { labels: { 'Ok': 'OK' } });
            return;
        }
        else if (data == "Usuário ou Senha inválidos.") {
            UIkit.modal.alert(data, { labels: { 'Ok': 'OK' } });
            return;
        }
        else {
            window.sessionStorage.setItem('acessos', JSON.stringify(data));//coloca os acessos em uma sessão.storage
            window.location.href = '#/';
        }
    })
    .error(function (error) {
        alert("Erro");
    });
};

The BackEnd is returning "Company not found." this can be seen in the following image

Butthecodeofif(data=="Empresa nao encontrada.") {...} does not execute, only the code of else is executed, because?

    
asked by anonymous 01.08.2016 / 00:42

1 answer

2

The code

.success(function (data) {
    //...
}

Returns the following object:

  

data - {string | Object} - The response body transformed with the transform functions.

     

status - {number} - HTTP status code of the response.

     

headers - {function ([headerName])} - Header getter function.    config - {Object} - The configuration object that was used to generate the request.

     

StatusText - {string} - HTTP status text of the response.

Font

So, for your code to work, you should reference the data that is where the answer itself is, thus:

if (data.data == "Empresa nao encontrada.") {
    UIkit.modal.alert(data, { labels: { 'Ok': 'OK' } });
    return;
} else if (data.data == "Usuário ou Senha inválidos.") {
    UIkit.modal.alert(data, { labels: { 'Ok': 'OK' } });
    return;
}
    
01.08.2016 / 01:08