I have a controller method that has been processing JSON requests for a long time analyzing this extension, but now I need to open it for the ajax cross domain, so I would like to suggest a JSONP option by analyzing this extension. I have already updated the file routes.php:
Router::parseExtensions( 'json', 'jsonp' );
So far so good, but happiness ends when the results turn out. Although the extension .jsonautomatically selects the layout json/default.ctp, the content .jsonpcontinues to accept a custom layout by default (and all its unnecessary HTML content). I tried to use RequestHandler::setContent()to set the content type of the response to both jsonand to js, but this is not like calling a call to the given layout directory.
Does anyone know what determines which layout directory for specific content? I tried creating jsonp/default.ctp, and I tried creating a layout js/default.ctpwith my JSONP result, but nothing seems to be happening. I just get normal by default.
Any insight into how extensions / content types are mapped to these layout directories would be greatly appreciated.
source
share