У меня есть проект, связанный с Webpack4, мне нужно взять некоторую информацию из входных данных формы и записать ее в текстовый файл. Я новичок в разработке, извините, если вопрос глупый
Итак, я создал сервер node.js, на котором мне нужно опубликовать эти данные, а затем записать в текстовый файл. Когда я пытаюсь сделать запрос 'Post' на мой локальный хост, он выдает ошибку 'Доступ к XMLHttpRequest в' file: /// E: / server / localhost: 3000 'from origin' http://localhost:9000' заблокирован CORSполитика: Запросы между источниками поддерживаются только для схем протоколов: http, data, chrome, chrome-extension, https. '. Как решить эту проблему.
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer((req, res) =>
{res.writeHead(200, {
'Content-Type':'text/html'
})
res.end('ggwp')}
)
server.listen(3000, () =>{
console.log('ok')
})
```here's my server
const bookForm = document.querySelector(".book-form");
const select = document.querySelector(".select");
const name = document.getElementsByName('name');
const number = document.getElementsByName('phone_number');
const xhr = new XMLHttpRequest();
export let fragment = '';
export function abc() {
bookForm.addEventListener("submit", e => {
e.preventDefault();
console.log(fs);
fragment += name[0].value + ' ' +number[0].value + ' ' + select.options[select.selectedIndex].text;
xhr.open('POST', 'file:///E:/server/localhost:3000', true)
xhr.send(fragment)
xhr.onreadystatechange = function() { // (3)
if (xhr.readyState != 4) return;
if (xhr.status != 200) {
console.log(xhr.status, xhr.statusText)
alert(xhr.status + ': ' + xhr.statusText);
} else {
alert(xhr.responseText);
}
}
});