Copy Code code as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
$weather = file_get_contents ("http://www.weather.com.cn/data/sk/101280601.html");
Echo $weather;
?>
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "TEXT/HTML;CHARSET=GBK"/>
<style type= "Text/css" >
. All spans {font:bold 30px/50px "Arial"; color:red}
</style>
<title> Weather Forecast </title>
<body>
<div class= "All" >
Here are: <span class= "Place" > City </span>
The temperature is <span class= "temp" > Temperature </span>
Wind Direction: <span class= "Wind" > Direction </span>
Wind: <span class= "Windpower" > Wind </span>
</div>
<script type= "Text/javascript" src= "Http://127.0.0.1/jquery.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$.ajax ({
The requested address
URL: "http://127.0.0.1/weather.php",
Functions executed after the request succeeds
Success:function (data) {
Converts a string to JSON format using eval () to parse the returned data
var OD = eval (' (' +data+ ') ');
Getting elements with jquery-1.8.2
var $place = $ (". Place"),
$temp = $ (". Temp"),
$wind = $ (". Wind"),
$windPower = $ (". Windpower");
Put the returned data to the appropriate location
$place. HTML (od["Weatherinfo"] ["City"]);
$temp. HTML (od["Weatherinfo"] ["temp"] + "°");
$wind. HTML (od["Weatherinfo"] ["WD"]);
$windPower. HTML (od["Weatherinfo"] ["WS"]);
}
});
})
</script>
</body>