为什么console.log('Your query count: ' , data);
显示为空?(连结果都成功了?调试控制台网络选项卡显示数据爬取成功)
清单.json:
{
"title": "API test",
"server": [
{ "agent": "abc",
"url": "def" },
],
}
索引.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>
你的代码对我有用,但试试
var read = JSON.stringify(data);
console.log('Your query count: ' , read );
代替
var read = JSON.stringify(data);
console.log('Your query count: ' , data);
编辑:哦,看起来你的 manifest.json 不是正确的 JSON。尝试删除逗号
{
"title": "API test",
"server": [{
"agent": "abc",
"url": "def"
}]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句