美文网首页Ajax
AJAX基础二

AJAX基础二

作者: 东邪_黄药师 | 来源:发表于2018-10-09 22:36 被阅读8次

    response与responseText 的对比:
    response(需要IE9以上)获取到的结果会根据 this.responseType 的变化而变化。
    responseText:永远获取的是字符串形式的响应体。

    var xhr = new XMLHttpRequest()
    xhr.open('GET', 'test.php')
    xhr.send()
    // 我们通过代码告诉请求代理对象,服务端响应给我们的是 JSON
    xhr.responseType = 'json'
    xhr.onreadystatechange = function () {
      if (this.readyState !== 4) return
      console.log(this.response
    }

    相关文章

      网友评论

        本文标题:AJAX基础二

        本文链接:https://www.haomeiwen.com/subject/ltkuaftx.html