Using JSON AJAX posts from PHP

Because I know I’ll need this again in the future, here’s how to use an AJAX request with a JSON body (such as how an AngularJS $resource posts) from within PHP: if ( array_key_exists(‘CONTENT_TYPE’, $_SERVER) && array_key_exists(‘CONTENT_LENGTH’, $_SERVER) && (strncmp($_SERVER[‘CONTENT_TYPE’], ‘application/json’, 16) === 0) && (intval($_SERVER[‘CONTENT_LENGTH’]) < 10000) ) { try { $bodyData = json_decode(file_get_contents(‘php://input’), […]