Created
October 27, 2011 19:17
-
-
Save meeDamian/1320546 to your computer and use it in GitHub Desktop.
[ PHP | lib ] respond from AJAX request
This file contains hidden or 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
<? | |
// remember to set proper headers! | |
/** | |
* RESPOND WITH VALID JSON STRING (FROM AJAX) | |
* it's more of a standard than a particular function =) . | |
* descriptions for below parameters are RECOMMENDED usage, each one of them can be of any type | |
** | |
* $success (bool) => if AJAX operation succeded | |
* $cause (string) => very quick explanation: "<type> <operation> <operation parameter>" | |
* $more (array) => if more info occured, here's the place to return it | |
** | |
* returns nothing; | |
* > exits execution | |
**/ | |
function respond($success, $cause, $more="") { // respond with normalized JSON format from all files requested by ajax | |
exit(json_encode(array('success'=>$success,'cause'=>$cause,'more'=>$more))); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment