Skip to content

Instantly share code, notes, and snippets.

@grvoyt
Last active February 7, 2019 14:46
Show Gist options
  • Save grvoyt/daabc65138fc89f45f76d5caa077b87f to your computer and use it in GitHub Desktop.
Save grvoyt/daabc65138fc89f45f76d5caa077b87f to your computer and use it in GitHub Desktop.
a little function to response json for ajax call
function json_response($data = array()) {
// clear the old headers
header_remove();
// set the actual code
http_response_code(200);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
// treat this as json
header('Content-Type: application/json');
header('Status: 200');
return json_encode($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment