}
if (!empty($requestParams['json'])) {
- CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
if (!empty($requestParams['prettyprint'])) {
- // Used by the api explorer
+ // Don't set content-type header for api explorer output
return self::jsonFormated(array_merge($result));
}
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
return json_encode(array_merge($result));
}
* Note: We have to manually execute the ajax in order to add the secret extra "prettyprint" param
*/
function execute() {
+ var footer;
$('#api-result').html('<div class="crm-loading-element"></div>');
$.ajax({
url: CRM.url('civicrm/ajax/rest'),
type: _.includes(action, 'get') ? 'GET' : 'POST',
dataType: 'text'
}).done(function(text) {
+ // There may be debug information appended to the end of the json string
+ var footerPos = text.indexOf("\n}<");
+ if (footerPos) {
+ footer = text.substr(footerPos + 2);
+ text = text.substr(0, footerPos + 2);
+ }
$('#api-result').text(text);
prettyPrint('#api-result');
+ if (footer) {
+ $('#api-result').append(footer);
+ }
});
}