Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created October 27, 2011 19:17
Show Gist options
  • Save meeDamian/1320546 to your computer and use it in GitHub Desktop.
Save meeDamian/1320546 to your computer and use it in GitHub Desktop.
[ PHP | lib ] respond from AJAX request
<?
// 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