简体   繁体   English

415 reactjs中不支持的媒体类型

[英]415 Unsupported Media Type in reactjs

I doing delete function to delete banner image.我做删除功能来删除横幅图像。 I have create a delete function as below:我创建了一个删除功能,如下所示:

 const [del, setDel] = useState([]); const DeleteBanner = async (banner) => { setDel(banner); console.log(del); Axios.delete(`/shop/${shopID}/banners`, del) .then((res) => { if (res.status === 200) { setMessage({ data: `${res.data.MESSAGE}`, type: "alert-success", }); onShowAlert(); } }) .catch((err) => { setMessage({ data: err.response.data.MESSAGE, type: "alert-danger", }); setLoading(false); onShowAlert(); }); }; return ( <div className=""> {shopData.data.ShopBanner.map((banners) => ( <Col md="6" xs="12" className="p-0 m-0" key={`img-${banners}`} href="#pimage" > <img className="border border-white" key={`img-${banners}`} src={`/api/v2/public/Shop/${shopID}/banner/${encodeURIComponent( banners )}`} style={{ padding: "5px" }} width="100%" height="100%" alt="banner" /> <Button className="btn-link" value={banners} onClick={(e) => { DeleteBanner(e.target.value); }} > Delete </Button> </Col> ))} </div> )

then I display the banner image from the database and add a delete button set the value to banners (which is the image id )然后我显示数据库中的横幅图像并添加一个删除按钮,将值设置为横幅(即图像 id)

the pic from swagger图片来自招摇在此处输入图像描述

when I try to delete, I'm getting the error 415 Unsupported Media Type, I'm not sure what went wrong.当我尝试删除时,我收到错误 415 Unsupported Media Type,我不确定出了什么问题。 The post method for post the banner image is in fromdata which I success to post but has problem in delete发布横幅图像的发布方法在我成功发布但删除有问题的fromdata中

Axios accepts two parameters: url and optional config . Axios 接受两个参数: url和可选的config You can use config.data to set the response body as follows:您可以使用config.data来设置响应正文,如下所示:
Refer : https://github.com/axios/axios/issues/897参考: https ://github.com/axios/axios/issues/897

axios.delete(URL, {
  headers: {
    'Accept': 'application/json'
  },
  data: del
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM