<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>原生异步</title>
<!--武汉近5天天气预报-->
</head>
<body>
<div id="showArea"></div>
<script>
//创建对象
var xmlhttp;
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xmlhttp = new XMLHttpRequest();
} else {
// IE6, IE5 浏览器执行代码
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//建立连接
xmlhttp.open("GET", "http://wthrcdn.etouch.cn/weather_mini?city=武汉", true);
//发送请求
xmlhttp.send();
//响应
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("showArea").innerHTML = xmlhttp.responseText
alert(xmlhttp.responseText);
}
}
</script>
</body>
</html>
使用原生JS-AJAX请求获取天气预报返回json对象,未作处理
最新推荐文章于 2022-04-16 01:24:21 发布