Stap 4: Output
Afdrukken output als JSON
echo json_encode(array("title"=>data));
dus totale code zal
<? phpheader ('Access Control-toestaan-oorsprong: *'); voor het accepteren van elke oorsprong zoals localhost, other.header ('Content-Type: application/json "); instelling koptekst als 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));?>
Zo wanneer u belt
yourdomain.com/API.php?action=time
resultaat zal worden
{"resultaat": "1440237956"}