return object returned from bank to front-end

Asked

Viewed 89 times

0

I don’t understand why you return

On the Node.js server:

//Insert user
router.post('/', async function(request, response) {
    let object = {
        name: request.body.userName, 
        password: request.body.userPassword
    }

    let insert = await serviceUser.insert(object);
    console.log(insert); //Aqui mostra todos os dados (id inserido, número de inserts, etc)
    response.send(insert);
});

No client in angular.js:

$http({
    method: 'POST',
    url: 'http://localhost:3000/user',
    data: {userName: 'teste', userPassword: '123abc'},
    mode: 'no-cors'
})
.then(function(response) {
    $scope.dataResponse = response;
    console.log(response); //Aqui aparece o header, status, ... e o atributo data (que contém o retorno do servivor) apenas com: { n: 1, ok: 1 }
})
.catch(error => console.log(error));

Why is that? I would like the server return to have other data, how do I do this?

Observing: data: { n: 1, ok: 1 }, on the front end, is equivalent to result: { n: 1, ok: 1 }, in the back-end, that is, this attribute is in the back but only it is returned and not whole parent object. I am not making any filter to return only the result

  • But the question has to do with the key in the return not being the same ? data in contrast to result ? Or the data you get from the client side is not the same ?

  • @Isac exactly, on the server I have the complete object and on the client I only have an object attribute

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.