Étape 4: sortie
Sortie d’impression au format JSON
echo json_encode(array("title"=>data));
donc code total sera
<? phpheader ("Access-Control-Allow-Origin: *') ; pour accepter n’importe quelle origine comme localhost, other.header ('Content-Type : application/json ') ; en-tête de réglage au format JSON <?phpheader('Access-Control-Allow-Origin: *'); // for accepting any origin like localhost ,other.header('Content-Type: application/json'); //setting header as JSON $action = $_GET['action']; switch($action){ case "time": $data=time(); //inbuilt time function in php returns UNIX timestamp break;case "store"://Store another input in db or filebreak;}echo json_encode(array("result"=>$data));?>
ainsi, lorsque vous appelez
yourdomain.com/API.php?action=Time
vous visualiserez
{« résultat »: « 1440237956 »}