Skip to content

Instantly share code, notes, and snippets.

@syuji-higa
Last active November 16, 2019 04:55
Show Gist options
  • Save syuji-higa/fb6a38b24b00b9038c14bd0e3c3e0e92 to your computer and use it in GitHub Desktop.
Save syuji-higa/fb6a38b24b00b9038c14bd0e3c3e0e92 to your computer and use it in GitHub Desktop.
PHP - get data with Ajax
<?php
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) ||
$_SERVER['HTTP_X_REQUESTED_WITH'] !== 'XMLHttpRequest') {
die(json_encode(array('status' => "Invalid call.")));
}
$value = array(
array('id' => 0, 'name' => 'taro', 'age' => '25'),
array('id' => 0, 'name' => 'jiro', 'age' => '20'),
);
header('Content-Type: application/json; charset=UTF-8');
header('X-Content-Type-Options: nosniff');
echo json_encode($value, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment