Skip to content

Instantly share code, notes, and snippets.

@radmiraal
Created February 7, 2013 22:31
Show Gist options
  • Save radmiraal/4734827 to your computer and use it in GitHub Desktop.
Save radmiraal/4734827 to your computer and use it in GitHub Desktop.
/**
*
*/
public function callActionMethod() {
if ($this->request->getFormat() === 'jsonp') {
try {
parent::callActionMethod();
} catch (\Exception $exception) {
$this->response->setContent(sprintf('<div class="alert alert-error">%s</div>', $exception->getMessage()));
}
$this->response->setHeader('Content-Type', 'application/javascript');
$content = $this->response->getContent();
$content = str_replace(array("\n", "\r", "\t"), '', $content);
$this->response->setContent(sprintf(
'%s(%s)',
$this->request->getArgument('callback'),
json_encode((object)array(
'html' => $content
))
));
} else {
parent::callActionMethod();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment