我想用AJAX将这个JSON数据加载到我的网站中。我该怎么办?
我的HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<h1>Authors</h1>
<ul id="authors"></ul>
</body>
</html>
我的Ajax代码:
function createNode(element) {
return document.createElement(element);
}
function append(parent, el) {
return parent.appendChild(el);
}
const xx = document.getElementById('authors');
const url = 'https://randomuser.me/api/?results=2';
fetch(url)
.then((resp) => resp.json())
.then(function(data) {
let authors = data.results;
return authors.map(function(authorz) {
let span = createNode('span');
span.innerHTML = '${authorz.gender}<br>';
append(xx, span);
})
})
.catch(function(error) {
console.log(JSON.stringify(error));
});
这可以按预期工作,但我想从
更改我的链接https://randomuser.me/api/?results=2
到
http://jiyo-hotel.com/ttm/mutiara.php
和
span.innerHTML = '${authorz.gender}'
到
span.innerHTML = '${authorz.kata}'
但它不起作用。