[Ajax plugin] Returning via Ajax data that are output by a PHP script that works after outputing data

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
Kamil Szmit
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue May 30, 2017 10:41 am

[Ajax plugin] Returning via Ajax data that are output by a PHP script that works after outputing data

Post by Kamil Szmit » Tue May 30, 2017 11:16 am

I have a method in a separate script "donation.php" Ajax plugin:

Code: Select all

function donateInitiation($req = null, $res = null) {
   // (...)   
                                   ob_end_clean();
                                   header("Connection: close\r\n");
                                   header("Content-Encoding: none\r\n");
                                   ignore_user_abort(true);
                                   ob_start(); 
                                   json($copy); // json = echo json_encode, returning data in JSON format
                                   $size = ob_get_length();
                                   header("Content-Length: $size"); 
                                   ob_end_flush();
                                   flush(); 
                                   ob_end_clean();
                                   if(session_id()) 
                                   {
                                        session_write_close();
                                   }
   // (...) - further operations
}  
Can I return the value that is output by the method "donateInitiation" in the main plugin script? I am trying to make it in this wy, but nothing is returned:

Code: Select all

jimport('joomla.plugin.plugin');
class plgAjaxLatestarticles extends JPlugin{
    function onAjaxLatestarticles()    {
        require_once "donation.php";
        $myShop->donateInitiation();return;
    }}  
Returning by the script "donation.php" works when I refer to it directly through Ajax, but this is not recommended in Joomla and often blocked at the server level. Returning data works as well when the data is returned at the end of the method call. Can I return data that is output with a construction "echo" by the PHP script that runs after the data is output in Joomla Ajax plugin ? Can I do something like this with a module or another type of Joomla extension? Could you help me?

Locked

Return to “Extensions for Joomla! 3.x”