简体   繁体   English

在 position 0 处的 JSON 中接收错误意外令牌 <; 这是后端还是前端问题?

[英]Receiving error Unexpected token < in JSON at position 0; is this a backend or frontend problem?

I currently have a PATCH method:我目前有一个 PATCH 方法:

export const patchEvent = (eventToUpdate) => dispatch => {
  fetch(`http://localhost:3000/events/${eventToUpdate.id}/`, {
      method: "PATCH",
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        workers_hired: eventToUpdate.workers_hired
      })
  })
    .then(res => res.json())
    .then(data =>{
      dispatch({
        type: PATCH_EVENT,
        payload: eventToUpdate.workers_hired
      })
    })
}

Which receives data from a React event:从 React 事件接收数据:

  const addWorker = () => {
    const viewedEvent = props.rawEvents.find(event => {
      return event.name === props.event.title
    })

    viewedEvent.workers_hired = 5

    props.patchEvent(viewedEvent)
  }

Where props.patchEvent is my Redux action that is shown in the first code snippet.其中 props.patchEvent 是第一个代码片段中显示的 Redux 操作。

When I fire this action I receive a 404 error "Unexpected token < in JSON at position 0"当我触发此操作时,我收到 404 错误“Unexpected token < in JSON at position 0”

Now, I understand that this has to do with the fetch response not being in correct JSON but I cannot for the life of me figure out where the formatting has gone wrong in my code.现在,我知道这与获取响应不正确有关 JSON 但我一生都无法弄清楚我的代码中的格式哪里出错了。 Any help would be greatly appreciated!任何帮助将不胜感激!

Error 404 means that the url you requested not found.错误 404 表示未找到您请求的 url。 Check if you fetch the correct url.检查您是否获取正确的 url。

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

相关问题 错误:位置 0 处的 JSON 中出现意外标记 &lt; - Error: Unexpected token < in JSON at position 0 SyntaxError 问题:JSON 中位置 0 的意外标记 K - Problem with SyntaxError: Unexpected token K in JSON at position 0 使用 manifest.json 接收错误(意外令牌) - Receiving error with manifest.json (unexpected token) localStorage 和 JSON.parse 的问题,错误:Uncaught SyntaxError: Unexpected token [ in JSON at position 1430 - problem with localStorage and JSON.parse, error : Uncaught SyntaxError: Unexpected token [ in JSON at position 1430 使用 React.js 问题获取本地 JSON object,错误:意外的令牌 &lt; 在 JSON 在 Z46057FE076FD4982A - Fetching local JSON object with React.js problem, Error: Unexpected token < in JSON at position 0 错误:语法错误:意外的标记{位于JSON中的位置4 - Error : SyntaxError: Unexpected token { in JSON at position 4 在位置0错误的JSON中出现意外的标记m - Unexpected token m in JSON at position 0 error JSON 中的意外标记 u 在位置 0 JS 中的错误 - Unexpected token u in JSON at position 0 Error in JS JSON 中的意外令牌 D 位于位置 1 错误 - Unexpected token D in JSON at position 1 error SyntaxError: Unexpected token &lt; in JSON at position 0&quot; 错误在 AJAX - SyntaxError: Unexpected token < in JSON at position 0” error in AJAX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM