I have a simple PHP script which returns a simple JSON response:
$data=array('a'=>'apple');
header('Content-Type: application/json');
print json_encode(array($date));
Using JavaScript, I try to read the data:
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);
}
};
The code works for the most part, but I cannot get anything for the responseType
property. I was expecting it to be json
but anything would be helpful.
I thought that a suitable mime type would do the job. I have tried it in Firefox, which has generally very good support, as well as in Safari.
What am I missing?