PHP gibt JSON -Daten an AJAX zurück
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
Grepper
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
// sent json data by post method or others
// {"id":"2"}
header('Content-Type: application/json');
// retrieve json data from post
$json = file_get_contents('php://input'); // return {"id":"2"}
$data = json_encode($json); // return a stdClass object| $data->id
echo $data->id;
<?php
echo json_encode($data);
?>