当前位置: 移动技术网 > IT编程>开发语言>PHP > 利用中国天气预报接口实现简单天气预报

利用中国天气预报接口实现简单天气预报

2019年03月31日  | 移动技术网IT编程  | 我要评论

10032500,考研作弊被抓,琼州学院分数线

复制代码 代码如下:

<?php
header("content-type:text/html;charset=utf-8");
$weather = file_get_contents("http://www.weather.com.cn/data/sk/101280601.html");
echo $weather;
?>

复制代码 代码如下:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gbk" />
<style type="text/css">
.all span {font:bold 30px/50px "宋体";color:red;}
</style>
<title>天气预报</title>
</head>
<body>
<div class="all">
这里是:<span class="place">城市</span>,
气温是<span class="temp">气温</span>,
风向:<span class="wind">风向</span>,
风力:<span class="windpower">风力</span>
</div>
<script type="text/javascript" src="http://127.0.0.1/jquery.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
//请求的地址
url : "http://127.0.0.1/weather.php",
//请求成功后执行的函数
success : function (data) {
//用eval()解析返回来的数据,将字符串转成json格式
var od = eval('('+data+')');
//用jquery-1.8.2获取元素
var $place = $(".place"),
$temp = $(".temp"),
$wind = $(".wind"),
$windpower = $(".windpower");
//将返回来的数据放到相应的位置
$place.html(od["weatherinfo"]["city"]);
$temp.html(od["weatherinfo"]["temp"] + "°");
$wind.html(od["weatherinfo"]["wd"]);
$windpower.html(od["weatherinfo"]["ws"]);
}
});
})
</script>
</body>
</html>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网