Friday, 13 July 2018

Why doesn't this work?

I'm trying to send a value to node, specifically postgres but it's not taking in the value.// html // jquery $('button').on('click', function(e) { let username = $(this).text(); $.post({ url: '/get-user', data: { username: username }, success: function(resp) { // do stuff } }) }) // server await client.query('SELECT * FROM users WHERE username = $1', [req.body.username]) It's returning 0 rows. However, if I hardcode the 'john' into username (on client or server side), I get results. Doing console.log of function text() or html() returns string. Console.log harded 'john' is also string. It seems jquery text() and html() function returns a string that cannot be interpreted by the server. If I store the username in an data attribute, it works too. I'm very curious as to why this is happening.

Submitted July 14, 2018 at 02:37AM by eggtart_prince

No comments:

Post a Comment