为什么console.log('Your query count: ' , data);
显示为空? (即使结果是成功和调试控制台网络选项卡显示的数据是成功抓取?)Javascript - 如何获取清单json并将其用作对象?
manifest.json的:
{
"title": "API test",
"server": [
{ "agent": "abc",
"url": "def" },
],
}
的index.php:
<script>
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
callback(null, xhr.response);
} else {
callback(status);
}
};
xhr.send();
};
getJSON('http://localhost/manifest.json',
function(err, data) {
if (err != null) {
alert('Something went wrong: ' + err);
}
else {
var read = JSON.stringify(data);
console.log('Your query count: ' , data);
}
});
</script>
还是一样的。即使有数据也是null。 – YumYumYum
编辑我的回答@YumYumYum –