1

I'm using fabrik to develop some applications, it's great. However I have the need to use ajax with it now, I know how to use it and I already have everything set up, but I need to fix the javascript code to do what I want, I want to use TCPDF with it, or basically just run a PHP function on demand.

This is my php code

public function doButton() {
    require_once JPATH_SITE . '/tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
        require_once(dirname(__FILE__).'/lang/eng.php');
        $pdf->setLanguageArray($l);
    }
    $pdf->SetFont('helvetica', '', 9);
    $pdf->AddPage();
    $contenido = array();
    $contenido[] = '<html>';
    $contenido[] = 'Test';
    $contenido[] = '</html>';
    $pdf->writeHTML(implode($contenido), true, 0, true, 0);
    $pdf->lastPage();
    ob_end_clean();
    $pdf->Output('test.pdf', 'D');
}

This is the javascript code I got and it works, but it's displaying an alert, I just want to run the function and send some input values through POST.

function doButton(el) {
    var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=doButton";
    new Request({url:url,
        onComplete: function(response) {
            if (response !== '') {
                alert(response);
            }
        }
    }).send();
}

I have a simple button that runs the javascript function doButton(this).

This may be dumb and simple, but I'm new to ajax and I can't find any similar code anywhere, seems to me like this ajax is using pure javascript, all examples I could find use jquery, which appears to not be supported and be completely different. I haven't found a single ajax with POST that doesn't use jquery.

This is basically what I want, but in pure javascript.

2
  • JQuery does work with Joomla!, but you may need to declare it depending on the template you're using. – James Shaver Dec 15 '20 at 18:18
  • You can use a fetch or XHR request, depending on your browser requirements. – Lodder Dec 16 '20 at 5:45
0

What do you mean by jQuery is not suppoted. It's included in Joomla core, so you should not have a problem with jQuery ajax.

Depending on where you use it, you might need to add JHtml::_('jquery.framework');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.