Clone de Netflix
3 mars, 2016
Clone loto 6/46 – VanillaJS
3 mars, 2016
 

Manipulation de données JSON en asynchrone (AJAX). Intégration d'un API externe

Javascript
AJAX
JSON
HTML
CSS
API openweathermap
<?php
 $api_key = '56f0c8d40a6948c0feba7ed12f04a7ea';
    $url = 'http://api.openweathermap.org/data/2.5/weather?id=6077243&units=metric&appid='.$api_key;
   $jsonstr = file_get_contents($url);
   $jsonobj = json_decode($jsonstr);
	$rep = "<h3>Météo</h3><i>".date('Y-m-d')."</i><br>";
	$rep.=$jsonobj->name."<br>";
	$rep.="Température :".$jsonobj->main->temp."°C<br>";
	$rep.="Min :".$jsonobj->main->temp_min."°C  Max : ".$jsonobj->main->temp_max."°C<br>";
	$rep.="<img src='http://openweathermap.org/img/w/".$jsonobj->weather[0]->icon.".png'>";
   echo utf8_encode($rep);
?>