ASP. Get JSON weather data across domains

Source: Internet
Author: User

A few days ago to do a portal site, on the home page need to load meteorological data, the use of the Central Meteorological Bureau interface.

Just started to use JSONP in the foreground cross-domain request data, did not succeed ~

After replacing the request data in C # back ...

Front-End Code:

        $ (function () {            $.ajax ({                type: "GET",                URL: "Service/getweather.ashx",                dataType: "JSON",                success : function (data) {                    var weatherms = ';                    Console.log (data);                    data = eval (data.weatherinfo);                    Weatherms + = ' City: ' + data.city+ ' weather conditions: ' +data.weather+ ' temperature: ' +data.temp2+ ' ~ ' +data.temp1;                    $ ("#innerWeather"). HTML (weatherms);                }            );        })

Background code:

            Context. Response.ContentType = "Text/plain";            Get weather and parse              HttpWebRequest request = (HttpWebRequest) httpwebrequest.create ("http://www.weather.com.cn/data/ Cityinfo/101110407.html ");            Request. Timeout =;            Request. Method = "GET";            HttpWebResponse response = (HttpWebResponse) request. GetResponse ();            StreamReader sr = new StreamReader (response. GetResponseStream ());            String jsonstr = Sr. ReadLine ();            Context. Response.Write (JSONSTR);

Input JSON directly to the foreground for processing.

Remember a little bit every day, convenient to use again later.

ASP. Get JSON weather data across domains

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.