I’m converting an EE2 addon to EE3. It has functionality to return AJAX responses on errors and success. For this I used to override Output.php (in memory) and send_ajax_response($data) instead of the standard response if ajax was set.
Is there a recommended way of doing this in EE3?
Specifically, what I’d like to do is hook onto Output->show_message() and display the output as JSON if the user is doing an AJAX request.
Why did you need to override Output and send_ajax_response? What are you doing differently that we weren’t?
If your CP controller is sending the response, you can just return an array like this:
return array(
'ajax' => TRUE,
'body' => array('some' => 'json data')
);
And we’ll automatically treat it as an AJAX response and encode the array you set in the body key as JSON. Does that do what you need?
Why are you looking to hook into show_message? Does this add-on return ALL EE system messages as AJAX or something?
Why are you looking to hook into show_message? Does this add-on return ALL EE system messages as AJAX or something?
Yes, specifically member registration. Any errors / or success message is returned via JSON if the user has specified ajax=’y’ in Simple Registration’s registration form. So SR basically hooks onto the member registration hooks to do its stuff, and then it lets EE do the actual creation of the member.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.