Node, Ajax and Rest silent error


#1

Hi,
I’m using express to build an api and I’m not getting any data or error back from this GET.
Any ideas?

$.ajax({
url:/userinfo,
method:‘GET’,
dataType: ‘json’,
data: {username:this.username, password:this.password, win:this.win, loss:this.loss},
success: function(result){
console.log(result);

},
error:function(err){
  console.log(err);
}

});

I don’t want to post my entire server file, I’m using app to call express here fyi.

app.get(’/public.userinfo’,(request, response) => {
client.query('SELECT * FROM userinfo WHERE userin_id, username=$1 AND password=$2 '[request.body.username, request.body.password],
result => response.send(result.row)
)
.catch(console.error);
});


#2

What does it mean that you don’t get any response? If you make that call, you should use an inspector / devtools to see what is returned for this XHR (AJAX) request.

My first guess would be 404. I think you have URL mismatch here, just take a closer look:

$.ajax({
   url:/userinfo,
   (...)
}
app.get(’/public.userinfo’ (...)

Although I may be wrong on this, since I don’t use node.js. You may also need to enclose your url in quotes? Since it’s a string.