代码拉取完成,页面将自动刷新
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Generator 函数
// 我们建议大家星号总是放在function后面
// function* getInfo(){
// yield "hello"
// yield "world"
// return "end"
// }
// var info = getInfo();
// console.log(info.next()); // {value: 'hello', done: false}
// console.log(info.next()); // {value: 'world', done: false}
// console.log(info.next()); // {value: 'end', done: true}
function* foo() {
yield 1
yield 2
yield 3
yield 4
yield 5
return 6
}
for (let i of foo()) {
console.log(i); // 1 2 3 4 5 没有6
}
</script>
</body>
</html> -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./jquery-3.6.0.min.js"></script>
</head>
<body>
<script>
// $.getJSON("http://iwenwiki.com/api/generator/list.php", function (data) {
// $.getJSON("http://iwenwiki.com/api/generator/id.php", { id: data[0] }, function (data) {
// $.getJSON("http://iwenwiki.com/api/generator/name.php", { name: data.name }, function (data) {
// console.log(data);
// })
// })
// })
// 把一个异步的操作变成一个同步的操作,但是实质上还是异步
function ajax(url) {
$.getJSON(url, function (data) {
info.next(data)
})
}
function* getInfo() {
var ids = yield ajax("http://iwenwiki.com/api/generator/list.php");
var names = yield ajax("http://iwenwiki.com/api/generator/id.php?id=" + ids[0]);
var infos = yield ajax("http://iwenwiki.com/api/generator/name.php?name=" + names.name)
console.log(infos);
}
var info = getInfo();
info.next()
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。