Answer the question
In order to leave comments, you need to log in
Why does the response from the server come 3 times?
On the client, ajax is generated on pure js (without jQuery). On the server I process on express.js
app.use(bodyParser.json());
app.post('/name', (req, res) => {
res.status(200);
});
form.addEventListener('submit', event => {
event.preventDefault();
var xhr = new XMLHttpRequest();
var json = JSON.stringify({
name: document.querySelector('#name-reg').value,
pass: document.querySelector('#pass-reg').value,
});
xhr.open('POST', '/name', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(json);
xhr.onreadystatechange = () => {
xhr.status === 200 ? console.log('Зарегистрирован') : console.log('не зарегистрирован');
};
});
Answer the question
In order to leave comments, you need to log in
Because somewhere in the code you request it three times. See not only the browser console, but also the network connections tab. Better yet, install fiddler and check it out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question