Javascript-форум (https://javascript.ru/forum/)
-   Node.JS (https://javascript.ru/forum/node-js-io-js/)
-   -   Ошибка acess-control (https://javascript.ru/forum/node-js-io-js/71926-oshibka-acess-control.html)

Hait 22.12.2017 00:46

Ошибка acess-control
 
Доброго времени суток. Реализую на node.js метод put, который должен добавить строку в таблицу. Но при запросе с клиента вылетает ошибка
Код:

Failed to load http://localhost:3000/schnedule/insert: Response to preflight request
 doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
 Origin 'null' is therefore not allowed access.

app.put("/schnedule/insert", function(req,res){
  console.log("tmp");
  connection.query("INSERT INTO schnedule (time, serviсeId, clientName, phoneNumber) VALUE (?, ?, ?, ?)", 
  [req.body.time,req.body.serviсeId, req.body.clientName, req.body.phoneNumber], function(err, rows){
    if (err){
      console.log(err);
      return;
    }
    res.writeHead(200, {
      'Access-Control-Allow-Origin' : '*',
      'Content-Type': 'text/plain; charset=UTF-8'
    })
  });
});


var send = function()
{
    var form = document.getElementById("form");
    var obj = new Object();
    obj["time"] = selectedTime.value;
    obj["serviceId"] = currentService.value;
    obj["clientName"] = form.elements[0].value;
    obj["phoneNumber"] = form.elements[1].value;
    var oReq = new XMLHttpRequest();
    oReq.open("PUT", "http://localhost:3000/schnedule/insert");
    oReq.setRequestHeader('Content-type', 'text/plain; charset=utf-8');
    oReq.send(JSON.stringify(obj));
}


Где я допустил ошибку? метод get, написанный аналогично, работает без проблем


Часовой пояс GMT +3, время: 15:37.