关于ajax异步访问数据的问题(ajax异步的原理)硬核推荐

随心笔谈11个月前发布 admin
95 0


<!DOCTYPE html>
<html lang=”zh-cn”>

<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<meta http-equiv=”X-UA-Compatible” content=”ie=edge”>
<title>ajax调用内涵段子</title>
<style>
video{
background-color: aquamarine;
}
</style>
<script src=”https://www.jb51.net/jquery-3.6.0.js”></script>
<script>
$(document).ready(function () {
xhttp=new XMLHttpRequest();
https=”https://api.apiopen.top/getJoke?page=1&count=2&type=video”;
xhttp.onreadystatechange=function(){
if(xhttp.readyState==4&&xhttp.status==200){
$(“h1”).html(JSON.parse(xhttp.responseText).result[0].text);
}
else{

}
}
$(“button”).click(function(){
xhttp.open(“GET”,https,true);
xhttp.send();
})
});
</script>
</head>
<button>点击获取</button>
<h1></h1>
<body>
</body>

</html>

© 版权声明

相关文章