Last active
February 7, 2019 14:46
-
-
Save grvoyt/daabc65138fc89f45f76d5caa077b87f to your computer and use it in GitHub Desktop.
a little function to response json for ajax call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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