jquery - javascript API call results in old data -
i have weather web api,which need show weather report of current city in website.whenever code calls in api, results in old data.data never changes , when run web api url on browser results want. please me reason cached data.
webapi
http://api.openweathermap.org/data/2.5/weather?lat=26.894049&lon=80.942686&mode=json
my code
$.getjson('http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + 'mode=json&rand=' + math.random(), function (data) { var wind = {}; var temp = {}; wind = data.wind; temp = data.weather; var clouds = '%' + data.clouds.all; var description = data.weather[0].description; var temp = data.main.temp - 273.15; var humidity = data.main.humidity + '%'; var icon = data.weather[0].icon; weatherimg = "<img height=\"45\" width=\"45\" style=\"border: medium none; width: 45px; height: 45px;position:relative;top:-10px; background: url('http://openweathermap.org/img/w/" + icon + ".png') repeat scroll 0% 0% transparent;\" alt=\"title\" src=\"http://openweathermap.org/images/transparent.png\">"; document.getelementbyid('weatherimg').innerhtml = weatherimg; document.getelementbyid('current_temp').innerhtml = (temp) + '°c'; document.getelementbyid('current_wind').innerhtml = ' ; ' + wind.speed + 'km/h'; document.getelementbyid('city_name').innerhtml = data.name; });
tested code working fine me time api response slow other every thing looks ok me
htttp://jsfiddle.net/navneetccna/un2u5j0v
Comments
Post a Comment