我有一个包含以下JSON的php页面
{"id":"1","name":"name1","books":[{"id":"1","title":"title1"},{"id":"2","title":"title2"}]}
我正在尝试获取此信息,但我不断获得以下输出:
name1 [object Object], [object Object]
我使用以下javascript代码进行获取:
window.onload=Send;
function Send() {
var buttonSend = document.getElementById("buttonSend");
buttonSend.onclick=HandleClick;
}
function HandleClick() {
var $id = document.getElementById("textAuthorID").value;
const URL = 'http://192.168.33.22/opdracht3/list.php?id=';
fetch(URL + $id)
.then( function(response) {return response.json(); })
.then( function(data){ writeOutput(data.name + " " + data.books.join(", ")); } )
.catch( function(exception) {writeOutput( exception );});
}
function writeOutput(text) {
var textNode = document.createTextNode(text + "\n");
var output = document.getElementById("divOutput");
output.appendChild(textNode);
}
有人可以帮我出示这些书的名字吗?