Service-side code
[HttpPost] public ActionResult GetWeather () {HttpWebRequest Request = (HttpWebRequest) httpwebrequest.create (
"
http://api.map.baidu.com/telematics/v3/weather?location= Xiamen &output= Json&ak=5slgyqgdenn7sy7pw29iuvrz
"
); HttpWebResponse response =
(HttpWebResponse) request. GetResponse (); Stream strstream =
response. GetResponseStream (); StreamReader sr =
new
StreamReader ( Strstream);
return
Content (Sr. ReadToEnd ()); }
Client code
<input type="Button"Value="Get the weather"Id="Btnok"/><div id="divcity"style="Display:none"> <span> City:</span> "<span id="txtcity"></span> "</div><div id="Divweather"></div><script src=".. /.. /scripts/jquery-1.4.4.min.js"Type="Text/javascript"></script><script type="Text/javascript">$ (function () {$ ("#btnOk"). Click (function () {$.post ("Home/getweather", {}, function (data, status) {if(Status = ="Success") { varJsondata =$.parsejson (data); if(Jsondata.status = ="Success"); { varJsonresult =Jsondata.results; varStrreslut ="<table ><tr> <th> dates </th><th> daytime </th><th> Night </th><th> Weather </th><th> Wind </th><th> temperature </th> </tr>"; $.each (jsonresult[0].weather_data, function (index, item) {Strreslut+="<tr><td>"+ Item.date +"</td><td>"+ Item.daypictureurl +"'/></td><td>"+ Item.nightpictureurl +"'/></td><td>"+ Item.weather +"</td><td>"+ Item.wind +"</td><td>"+ Item.temperature +"</td></tr>"; }); Strreslut+="</table>"; $("#divWeather"). HTML (""); $("#divCity"). CSS ("Display",""); $("#txtCity"). HTML (jsonresult[0].currentcity); $("#divWeather"). Append (Strreslut); } } Else{alert ("Ajax request failed! "); } }); }); });</script>