Задать вопрос
@heIIfire

Как получить JSON от клиента в ExpressJS?

Вот запрос AJAX

const data = { 
                         name: "vasya", 
                         age: 32 
            };
            let xhr = new XMLHttpRequest();
            xhr.open("POST", "/sign-in");
            xhr.setRequestHeader("Content-type", "application/json");
            xhr.onreadystatechange = function() {//Call a function when the state changes.
                if(xhr.readyState == 4 && xhr.status == 200) {
                   console.log(xhr.responseText);
                }
            };
            xhr.send(JSON.stringify(data));


На сервере request.body пусто - {}
  • Вопрос задан
  • 215 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы