-3
I have an application on Node.js in an Ubuntu VPS 18.4, but when trying to make a login request for testing, I get a Google Chrome error; "net::ERR_CONNECTION_REFUSED". He tells me he had some problem with the XHR answer.
AJAX code:
let click = document.querySelector('#botao')
let email = document.querySelector('#email')
let senha = document.querySelector('#senha')
click.addEventListener('click', function () {
$.ajax({
type: "POST",
url: "http://localhost:3000/autenticacao",
data: { email: email.value, senha: senha.value },
success: function (data) {
console.log(data.email , data.senha)}});})
Back Code:
module.exports = (app) => {
app.post('/autenticacao', function (req, res) {
let email = req.body.email
let senha = req.body.senha
res.json({email, senha })});}
I am using an NPM package that enables CORS. Below:
const cors = require('cors');
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE');
app.use(cors());
next();});
Application link: http://45.15.24.156/
Because it does not return the browser console the data entered in the login ?
Thank you !