Javascript encapsulate QQ weather forecast Interface

Source: Internet
Author: User

Currently, there are many websites that provide weather forecast services. Generally, they are used directly on their own websites. Some websites provide Web service interfaces.

    • Common Regular Expressions:The common method to reference weather forecasts is to use regular expressions to parse the weather forecasts of a specified website. This method has some drawbacks: 1. the HTML format of a personal website has changed. YourProgramYou need to modify it. 2. It is not easy to write the parsed regular expressions. 3. Access to others' websites for each resolution. When an exception occurs on others' websites, your program may be dragged down. Of course, you can solve some problems from your application process.
    • Web service interface:This is of course the first choice. Generally, websites that provide Web service interfaces are relatively stable.

If your website only needs to display the weather forecast for one region, use it directly. If you need to display the weather forecast for multiple regions, you may need to create your own IP address library. On that day, I saw that QQ provided some such services, So I simply studied it and found several useful interfaces. Among them, I am most satisfied that these interfaces are implemented in JavaScript and can be easily compatible with various website systems. However, the encoding format is gb2312 ~

I use jquery to call, and all calls are based on the results of http://minisite.qq.com/js/j.minisite.weather.js research.

Obtain the region and IP address of the current Browser:

$ J. getscript ("http://fw.qq.com: 80/IPaddress", function (){
If (typeof ipdata! = "Undefined "){
// Yoyosite. Cookie. Set ("current_ip", ipdata [2] + ',' + ipdata [3]);
Alert (ipdata );
}
});

I have simply encapsulated the current weather. Here I only describe how to use it (......, This weather forecast is not accurate ):

<Script language = "JavaScript" src = "http://www.greatmoo.com/untest/samples/js/jquery.js"> </SCRIPT>
<Script language = "JavaScript" src = "http://www.greatmoo.com/untest/samples/weather/weather.js"> </SCRIPT>
<Div id = "weather_content"> </div>

<Script language = "JavaScript">
Weather. INIT ("weather_content ");
</SCRIPT>

The calling method is very simple.Weather_contentThis keyword.

application instance: Success.

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.