Modification of the Ajax component so that the user can return a JSON object. #43471
-
} elseif (\is_scalar($results)) {
// Output string/ null
$out = (string) $results;
} else {
// Output array/ object
$out = implode((array) $results);
} In the com_ajax component, the returned Do I need to do PR or is this normal behavior? Should we make the code more flexible? I suggest adding a check to see if the object is a JSON type or not. } elseif (\is_scalar($results) || $results instanceof JsonResponse) {
// Output string/ null
$out = (string) $results;
} else { components/com_ajax/ajax.php) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Something like this is possible since 5.0, And the event listener, kind of: public function onAjaxFooBar(Joomla\CMS\Event\Plugin\AjaxEvent $event)
{
$response = ['foo' => 'bar', 'bar' => 'foo'];
$event->updateEventResult($response);
} It set the array, which will be passed to |
Beta Was this translation helpful? Give feedback.
-
I know that you need to install the JSON format for this. But I needed to pass the format as DEBUG, but at the same time so that the format was in JSON. The problem is that the object that generates the JFactory::getApplication()->enqueueMessage('Error Message'); so that later the JSON contains the service information of error messages. So I need to pass JSON from component c with messages. but the component does not transmit them, but calls JSON to form itself. thus, we need to achieve a JSON mode with error messages. And to do this, you need to add support for this feature, as I indicated in the main description. |
Beta Was this translation helpful? Give feedback.
-
I have made PR for it, please test #43530 |
Beta Was this translation helpful? Give feedback.
I have made PR for it, please test #43530