Embed from API REST data

Embed from API REST data

Ad esempio per chiedere che tempo che fa a …
Roma, Firenze, Palermo o Milano? 
dal servizio Open Weather Map
(All data are provided under the CC-BY-SA 2.0 see details here)


<script src=“//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script>

<script type=“text/javascript”>

function stampa(data) {
 if(data.cod!=‘200’||data.count<1) {
  alert(“Nessuna rilevazione trovata.”);
 } else {
  var newdiv = “<div id=’daticity’>
 A ” + data.list[0].name +
   “ adesso c’&egrave; una temperatura di ” +
   data.list[0].main.temp + “ &deg;C” + “ ed il tempo &egrave: <img src=’http://www.openweathermap.org/img/w/” + 
   data.list[0].weather[0].icon + “’ alt=’” +  data.list[0].weather[0].main +
   “’ title=’” +  data.list[0].weather[0].main + “’>” + “</div>
”;
  jQuery(‘div#daticity’).replaceWith(newdiv);
 }
}


function
getdataCitta(city) {
    var ajCall = $.Deferred();

    var url = “http://api.openweathermap.org/data/2.1/find/name?q=”;
    url = url + city;
    url = url + “,IT&units=metric”;

    $.ajax({
        type : “POST”,
        dataType : “jsonp”,
        url : url + “&callback=?”,
        async : false,
        success : function(data) {
            stampa(data);
        },
        error : function(errorData) {
            alert(“Errore durante il caricamento dei dati : ” + errorData.status);
        }
    });
    return ajCall.promise();
}
</script>




Try getdataCitta(’roma’);