【发布时间】:2015-12-05 02:07:37
【问题描述】:
我有一个简单的 PHP 脚本,它返回一个简单的 JSON 响应:
$data=array('a'=>'apple');
header('Content-Type: application/json');
print json_encode(array($date));
使用 JavaScript,我尝试读取数据:
var url='…';
var xhr=new XMLHttpRequest();
xhr.open('get', url, true);
xhr.send(null);
xhr.onreadystatechange=function() {
if(this.readyState==4) {
alert(this.responseText);
alert(this.responseType);
}
};
该代码大部分都有效,但我无法为 responseType 属性获取任何信息。我期待它是json,但任何事情都会有帮助。
我认为合适的 mime 类型可以胜任这项工作。我已经在 Firefox 和 Safari 中尝试过,它通常具有很好的支持。
我错过了什么?
【问题讨论】:
-
找到这个 (stackoverflow.com/questions/9845401/…)。似乎所有浏览器都不支持 responseType JSON
标签: javascript php json ajax xmlhttprequest