


PHP ajax achieves no refresh to obtain weather status_PHP tutorial
Jul 13, 2016 am 10:44 AMFirst of all, we must understand that we cannot do weather forecasting by ourselves. Here we only need to call the data returned by the API interface. The following is an example of calling the API interface of China Weather Network for us to learn together. Weather has become an indispensable topic in life and is closely related to our lives. On the right side of my blog, I made a small weather query module using php+ajax.
The ideal state should be for users to automatically obtain local weather information based on different places they visit. However, the technology is currently limited and can only be completed manually. This is much simpler and does not use too many technologies. It mainly uses ajax to call an open interface and then processes the returned json data.
Interface address: http://www.weather.com.cn/data/cityinfo/101200101.html
Returned value: {"weatherinfo":{"city":"Wuhan","cityid":"101200101","temp1":"28℃","temp2":"36℃", "weather":"Sunny to cloudy","img1":"n0.gif","img2":"d1.gif","ptime":"18:00"}}
The interface address part is "101200101". This string of ID numbers is the city ID. I went to Baidu to get the ID corresponding to the city, and then encapsulated it into an array. When using it, just call it directly. There is not much core code, mainly cities - IDs are relatively large, so I won’t post the source code, just package it and share it. Friends who need it can download it directly!
Part of the code
The code is as follows | Copy code | ||||
|
getweather.php文件
代码如下 | 复制代码 | ||||
请输入城市:<input type="text" name="city" id="city" value="武汉" /> <input type="button" name="sub" id="submit" value="查看天气" /> </form>
为、<?php
|
测试效果
源码下载:php ajax实现无刷新获取天气状态源码下载:
TechArticle
Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
