发生这种错误,会导致接收不到服务端返回的数据
Uncaught DOMException: Failed to read the responseText property from XMLHttpRequest: The value if only accessible if the object’s responseType is ‘’ or ‘text’ (was arraybuffer)

  • ArrayBuffer 字节数组,通常在其他语言中称为“byte array”

Uncaught DOMException: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘json’)

Failed to construct ‘URL’: Invalid URL
error Uncaught SyntaxError: Failed to construct ‘WebSocket’: The URL ‘[object Object]’ is invalid

  1. iframe.getAttribute('src') to just frame.src
  2. var base = 'http://localhost:6001/'
  3. var src = iframe.getAttribute('src') // 'iframe.html?id=*&viewMode=story'
  4. new URL(src, base)

wx.request

wx.request中的“responseType”项只有两种选项

  • ‘’
  • ‘text’,之前一直用的 ‘json’,将json修改成text就可以正常收到数据了

排除点,检查返回的数据的Content-Type 类型

  1. wx.request({
  2. url: 'http://localhost:8000/v1/user',
  3. data: {},
  4. header: {
  5. 'content-type': 'application/json'
  6. },
  7. responseType : 'json',
  8. success (res) {
  9. console.log(res)
  10. }
  11. });