I'm using PDFMerger to merge PDFs but when i attempt to call the file that merges the pdfs merge.php by using ajax i get a 500 internal server error.  When i type the file in the browser there is no 500 internal server error.
Here is the merge.php file.
$arr = $_REQUEST['idArray'];
include 'PDFMerger.php';
$pdf = new PDFMerger;
$i=0;
foreach($arr as $value) {
    $arr2[$i] = $value;
    $i++;
}
$filename = implode("-",$arr2);
$loop = 0;
$pdf->addPDF('samplepdfs/'.$arr2[0].'.pdf', 'all');
foreach($arr2 as $values) {
    if($loop>0) {
        $pdf->addPDF('samplepdfs/'.$arr2[1].'.pdf', 'all')
    }
    $loop++;
}
$pdf->merge('file', 'samplepdfs/'.$filename.'.pdf');
Here is the ajax function
$.ajax({
            url:"https://www.example.co.uk/wp-content/mpdf/examples/merge.php", //page to merge PDFs
            data: { idArray : id_array },
            type:'POST',
            success:function() {
}
});
Why do i get a 500 internal server error when using ajax with this file?
How do i solve this? I need to merge PDFs using ajax so i can print multiple PDFs at once.
 
    