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.
fetch
orXHR
request, depending on your browser requirements.