<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var user = JSON.parse(this.responseText);
var user1 = JSON.parse(xmlhttp.responseText);
console.log(user);
console.log(user);
// document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
document.getElementById("myDiv").innerHTML = user.jokes;
}
}
xmlhttp.open("GET",'https://autumnfish.cn/api/joke/list?num='+10,true);
xmlhttp.send();
}
function loadXMLDoc() {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var user = JSON.parse(this.responseText);
var jokes = user.jokes;
var output = '';
for (var i in jokes){
output +=`<ul>
<li>${jokes[i]}</li>
</ul>`
}
document.getElementById("myDiv").innerHTML = output;
} else if (this.status == 404) {
console.log("请求页面不存在");
}
}
xmlhttp.open("GET",'https://autumnfish.cn/api/joke/list?num='+10,true);
xmlhttp.send();
}
function loadXMLDoc() {
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xnlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var user = JSON.parse(this.responseText);
} else if (this.status == 404) {
console.log("请求页面不存在");
}
}
xmlhttp.open("GET",'https://autumnfish.cn/api/joke/list?num='+10,true);
xmlhttp.send();
}
</script>
<style>
div{
margin: 100px;
color: red;
background: #eee;
font-size: 20px;
}
button{
margin: 100px;
}
</style>
</head>
<body>
<div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
<button type="button" onclick="loadXMLDoc()">修改内容</button>
</body>
</html>