3

При совершении DELETE-запроса выбрасывает ошибку:

OPTIONS http://localhost:30117/api/Goods 405 (Method Not Allowed)

Fetch API cannot load http://localhost:30117/api/Goods. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8070' is therefore not allowed access. The response had HTTP status code 405. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Error: TypeError: Failed to fetch

На Web Api сервере включен CORS. На клиенте для отправки запроса использую модуль request:

function _delete(tableName, id) {
    return new Promise(function(resolve, reject) {
        request({
            method: "DELETE",
            url: `${_serverAddress}/${tableName}`,
            headers: {
                "Accept": "application/json"
            }
        }, function(error, response, body) {
            if (error) {
                reject(error);
            } else {
                resolve(body);
            }
        })
    });
}

GET-запросы работают нормально.

1
  • Ошибка оказалась достаточно простой: url: ${_serverAddress}/${tableName}, в данном месте забыл указать параметр id
    – user190794
    20 фев 2017 в 7:23

1 ответ 1

1

Надо обработать на сервере OPTIONS-запрос и выставить соответствующий Access-Cobtrol-Allow-Origin.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.