header('Content-type: application/json');
echo json_encode($array);
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
//In JS File
//JQUERY AJAX
$.ajax({
url: "path/to_php_file.php",
dataType: "json",
type: "GET",
data: {datax : datax },
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
$data = json_decode($json);
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
$json = '
{
"type": "donut",
"name": "Cake",
"toppings": [
{ "id": "5002", "type": "Glazed" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5004", "type": "Maple" }
]
}';
$yummy = json_decode($json);
print_r($yummy);
$str_json = file_get_contents('php://input');
<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);