AJAX基础二

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
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容