TomKing9 2021-12-19 14:56 采纳率: 77.8%
浏览 23
已结题

为什么Ajax请求监听的onreadystatechange函数触发是从2开始的而不是从1开始的

代码

const xhr = new XMLHttpRequest

xhr.open('GET', './data/test.json', true)

xhr.send(null)

xhr.onreadystatechange = () => {
  console.log(xhr.readyState)
  if (xhr.readyState === 4) {
    if (xhr.status === 200) {
      console.log(JSON.parse(xhr.responseText))
    } else if (xhr.status ===404) {
      console.log('404 not found')
    }
  }
}


结果:

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月27日
    • 创建了问题 12月19日

    悬赏问题

    • ¥15 Arcgis pro制图
    • ¥15 vivado综合时间过长
    • ¥15 uniapp时间组件切换语言问题
    • ¥15 求解惑:NPOI在excel中插入图片失败
    • ¥15 寻找基于运营商机顶盒的播放器
    • ¥15 fluent二维平板强迫振动
    • ¥15 Matlab画图-给图加上方向
    • ¥15 springboot+Python模型训练 有偿
    • ¥15 关于SQL Server数据库备份还原设置
    • ¥15 the HDL complexity tool使用问题