We often see some websites showing weather information, how does it come out? Let's share some of the ways that JS calls the weather API today.
Online can also find a lot of methods, but is generally free of bad use, good not free.
Previously used the weather API Sina, query the day and tomorrow's weather is still OK (although not very accurate), then there is a need to query seven days of demand, tried a lot of times can not, only a way out.
Find a www.k780.com/on the internet seems to be foreign, need to register, get to the interface required parameters Appkey and sign value, currently no charge, the following code to stick out, with comments
varParamurl = "http://api.k780.com:88/?app=weather.future&weaid=" + URL + "&appkey=" + Appkey + "&sign= 27c89ecea48a0e28f9c25f23be6a4e40&format=json "; $.ajax ({url:paramurl, type:"Get", DataType:"Jsonp", Jsonp:' Jsoncallback ', Async:false, Data:"", //Success:eval (Funback) is encapsulated as a method, here is the callback parameter nameSuccessfunction(data) {//This handles the returned results in JSON format. } });
Where Weaid: Address, can be name can be Ip,appkey sign is registered to get
Return the result, return the value of seven days, here only to intercept the day, which is worth mentioning is the Weather_icon field, the weather picture, there are several versions of the large map of the small map, can be downloaded on the website
{"Success": "1", "result": [{"Weaid": "2071", "Days": "2016-06-01", "Week": "Wednesday", "Cityno": "Hbyangxin", "citynm": "Sanyo", " Cityid ":" 101200603 "," Temperature ":" 28℃/20℃ "," humidity ":" 0℉/0℉ "," Weather ":" Rainstorm to drizzle "," Weather_icon ":"/HTTP// Api.k780.com:88/upload/weather/d/10.gif "," Weather_icon1 ":" Http://api.k780.com:88/upload/weather/n/7.gif "," wind ":" North Wind "," WINP ":" Level 3-4 "," Temp_high ":" "," "Temp_low": "0", "humi_low": "0", "Weatid": "One", "Weatid1": " 8 "," Windid ":" "," Winpid ":" 14 "}]}
Always say this is still relatively good use, the parameters are few, the return value is clear and complete. There is an AJAX request cross-domain problem, it is not clear that the use is not a problem, and so to understand the additional
JS Get the Weather