[英]axios req failed Error: Request failed with status code 404 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad
my patch request is not working.When I make patch request without AsyncThunk , it works fine and doesn't give any error but when using Thunk it fails and giving following error.我的补丁请求不起作用。当我在没有AsyncThunk的情况下发出补丁请求时,它工作正常并且没有给出任何错误,但是当使用 Thunk 时它失败并给出以下错误。 Error can be seen here in this image在这张图片中可以看到错误
[.[enter image description here][1]][1] I am sending postData(underlined blue).but I am unable to find why it is showing payload undefined. [.[在此处输入图像描述][1]][1] 我正在发送 postData(带下划线的蓝色)。但我无法找到它显示未定义有效负载的原因。 [![enter image description here][2]][2] Plus I am passing 2 values as object to "asyncThunk" because it takes only one argument as a payload.Is that is the problem or not! [![在此处输入图像描述][2]][2] 另外,我将 2 个值作为 object 传递给“asyncThunk”,因为它只需要一个参数作为有效负载。这是否是问题所在! [![enter image description here][3]][3] [![在此处输入图像描述][3]][3]
export const updatePost=createAsyncThunk(
'Post/updatePost',
async({id,updatePost})=>{
try{
const {data}=await api.updatePost(id,updatePost);
console.log(data)
return data;
}catch(err){
console.log('axios patch req failed',err)
}
}
)
const postSlice=createSlice({
name:'Post',
initialState:{
posts:[],
status:'failure'
},
extraReducers:{
[updatePost.fulfilled]:(state,action)=>{
console.log(action.payload)
state.status='success'
return state.posts.map((post)=>post._id === action.payload._id ?action.payload :post)
},
[updatePost.pending]:(state,action)=>{
state.status='pending'
console.log('pending due to',action)
},
[updatePost.rejected]:(state,action)=>{
state.status='rejected'
console.log('updatePost is rejected',action)
}
}
})```
** here is my patch request function **
```export const updatePost=(id,updatePost)=>axios.patch(`${url}/${id}`,updatePost)```
** dispatching my action **
```dispatch(updatePost({currentId,postData}))```
[1]: https://i.stack.imgur.com/Wb37y.png
[2]: https://i.stack.imgur.com/86a4l.png
[3]: https://i.stack.imgur.com/o0CLP.png
Upon looking in the error image it is showing that something in the data is being sent as undefined
I suggest console.log and check what is sent as undefined and try to resolve that or update the question with some other information as well.在查看错误图像时,它显示数据中的某些内容正在以undefined
的形式发送,我建议 console.log 并检查以未定义形式发送的内容并尝试解决该问题或使用其他一些信息更新问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.