飞行前响应中Access

飞行前响应中Access

本文介绍了飞行前响应中Access-Control-Allow-Methods不允许使用方法PATCH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ReactJS中使用axios PATCH方法更新记录,但记录失败并出现以下错误

I am using axios PATCH method in ReactJS to update the record but its getting failed with following error

这是我的动作:

export const UPDATE_AD_SLOTS_REQUEST = 'UPDATE_AD_SLOTS_REQUEST';
export const UPDATE_AD_SLOTS_SUCCESS = 'UPDATE_AD_SLOTS_SUCCESS';
export const UPDATE_AD_SLOTS_ERROR = 'UPDATE_AD_SLOTS_ERROR';


export function updateAdslotsRequest(){
  return {
    type: UPDATE_AD_SLOTS_REQUEST
  }
}

export function updateAdslotsSuccess(data){
  return {
    type: UPDATE_AD_SLOTS_SUCCESS,
    data: data
  }
}

export function updateAdslotsError(errors){
  return {
    type: UPDATE_AD_SLOTS_ERROR,
    erros: errors
  }
}

export function updateAdslots(data, id) {
  return dispatch => {
    dispatch(updateAdslotsRequest());
    return axios.patch(`http://192.168.99.100:8080/adslots/${id}`, data)
      .then(res => {
        dispatch(updateAdslotsSuccess(res.data));
      })
      .catch(errors => {
        dispatch(updateAdslotsError(errors));
      })
  }
}

我完全困惑.

推荐答案

您要调用的api必须允许PATCH请求.他们可以通过将Access-Control-Allow-Methods标头设置为也包含Patch来完成此操作.查找如何使用api使用的任何服务器端语言来执行此操作.您也可以尝试将呼叫切换为POST请求,但这更多是临时解决方法.

The api you are making the call to has to allow PATCH requests. They can do this by setting the Access-Control-Allow-Methods header to also have Patch in it. Look up how to do this with whatever server side language your api is using. You could also maybe try switching your call to a POST request but that is more of a temporary fix.

这篇关于飞行前响应中Access-Control-Allow-Methods不允许使用方法PATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:32