简体   繁体   English

axios req failed 错误:在 XMLHttpRequest.handleLoad 结算时(settle.js:17),在 createError(createError.js:16)处请求失败,状态码为 404

[英]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.

相关问题 错误:在 XMLHttpRequest.handleLoad (xhr.js:62) 结算 (settle.js:17) 时的 createError (createError.js:16) 请求失败,状态码 404 - Error:Request failed with status code 404 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:62) Axios createError.js:16 Uncaught (in promise) 错误:请求失败,状态码 400 - Axios createError.js:16 Uncaught (in promise) Error: Request failed with status code 400 createError.js:16 Uncaught (in promise) 错误:请求失败,状态码为 400 - createError.js:16 Uncaught (in promise) Error: Request failed with status code 400 createError.js:16 Uncaught (in promise) Error: Request failed with status code 400 反应 - createError.js:16 Uncaught (in promise) Error: Request failed with status code 400 in react 我该如何解决 index.js:1 错误:网络错误 *at createError (createError.js:16) *at XMLHttpRequest.handleError (xhr.js:117 - How can i solve it index.js:1 Error: Network Error *at createError (createError.js:16) *at XMLHttpRequest.handleError (xhr.js:117 出现错误:API 调用的 XMLHttpRequest.g.onerror (xhr.js:117) 处的 e.exports (createError.js:16) 网络错误 - Getting Error: Network Error at e.exports (createError.js:16) at XMLHttpRequest.g.onerror (xhr.js:117) for API call 如何在axios Next js中修复“错误:请求失败,状态码为404” - How to fix, “Error: Request failed with status code 404” in axios Next js 错误:React JS 中的请求失败,状态代码为 401 axios - Error: Request failed with status code 401 axios in React JS Axios - [未处理的承诺拒绝:错误:请求失败,状态码为 404] - Axios - [Unhandled promise rejection: Error: Request failed with status code 404] 错误:请求失败,状态码为 404,React,Axios - Error: Request failed with status code 404, React, Axios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM