Phpajax allows you to get the weather status without refreshing.

Source: Internet
Author: User
First, we need to understand that we cannot do the weather forecast function by ourselves. here we only need to call the data returned by the api, the following is an example of how to call the api of www.weather.com.cn. The weather has become an indispensable topic in life... first, we need to understand that we cannot do the weather forecast function by ourselves. here we only need to call the data returned by the api, the following is an example of how to call the api of www.weather.com.cn.
Weather has become an indispensable topic in our life and is closely related to our life. on the right side of my blog, I used php + ajax to create a weather query module.

The ideal status should be that the user automatically obtains local weather information based on different access locations, but the current technology is limited, and only manual query can be completed. This is much simpler, and too many technologies are not used. The main reason is that ajax is used to call an open interface and then process 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": "Clear to cloudy", "img1": "n0.gif", "img2": "d1.gif", "ptime "}}


The interface address section is "101200101". This ID string is the city id. the ID corresponding to my Baidu to City is encapsulated into an array and can be called directly when used. There are not many core code, mainly because the city -- the ID is relatively large, so I will not post the source code, just package it and share it directly. A friend in need can download it directly!

Some code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.