Why am I getting an 'XML parsing error' after using the Buttons excelHtml5 extension?

Why am I getting an 'XML parsing error' after using the Buttons excelHtml5 extension?

chrwic1chrwic1 Posts: 2Questions: 1Answers: 0

I'm sorry but I do not think I'm able to link my page to test. Here is my DataTable instantiation:

var table = $("#iSaleInvTable").DataTable({
        "destroy": true,
        "processing": true,
        "serverSide": true,
        "iDisplayLength": 100,
        "lengthMenu": [[25, 50, 100, 250, 500, 1000, 2500, -1],[25, 50, 100, 250, 500, 1000, 2500, 'All']],
        "autoWidth": false,
        "orderClasses": false,
        "colReorder": true,
        "ajax": {
            "url": systemURL + "inventoryInquiry/getSaleItems.php",

            "data": {
                        "location_filter": function () {
                        return $("#depotFilter").val();
                        },
                        "category_filter": function () {
                        return $("#categoryFilter").val();
                         },
            }
        },
        "columns":columns,
        "dom": 'Blirftp',
                "buttons": [
                     {
                          extend: 'excelHtml5',
                          title: 'Sale Inventory'
                      }
                 ],
    });

I'm getting the body of the table with this code:

$returnArr = SSPComplex::query( $_GET, $table, $joins, $primaryKey, $columns, $extraWhere);
// $returnArr['err'] = $debug ? $db->getLastError() : "";
$out = [];
foreach($returnArr['data'] as $data){
    $row = array();

    $row['item_code'] = $data['item_code'];
    $row['item_desc'] = $data['item_desc'];
    $row['category_name'] = $data['category_name'];
    $row['mfr_name'] = $data['mfr_name'];
    $row['depotNum'] = $data['depotNum'];
    $row['branchname'] = $data['branchname'];
    $row['total_in_stock'] = $data['total_in_stock'];
    $row['average_price'] = IntlHelper::formatCurrency($data['average_price']);
    
    $out[] = $row;
}

$returnArr['data'] = $out;

die(json_encode($returnArr));

The data exports into an .xlsx file just fine, but I can't get rid of the error that outputs after clicking the button to export the data.

The error shows:

XML Parsing Error: not well-formed
Location:
Line Number 1, Column 392:
XML Parsing Error: not well-formed
Location:
Line Number 1, Column 247:
XML Parsing Error: not well-formed
Location:
Line Number 1, Column 392:

Any direction as to why this is happening is greatly appreciated.

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    WE would need to see this to be able to understand the problem, as the export works fine on our examples. You don't need serverSide, just have the data local and load with data. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • chrwic1chrwic1 Posts: 2Questions: 1Answers: 0

    I was able to fix the error thrown by updating jQuery to the current version.

  • yayikesyayikes Posts: 4Questions: 0Answers: 0
    edited May 2021

    +1 seeing the same error, exactly as stated by @chrwic1 earlier, with same line numbers.

    The export works just fine, even with the errors. The error messages only appear within the Console, within the Firefox Developer Tools. Chrome does not report any errors at all.

    Using DataTables 1.10.20 and unfortunately stuck in jQuery 1.11.3 (not easy to upgrade).

    I read elsewhere the issue may be because the Content-Type header is not being sent. Firefox assumes XML, probably because XLSX is XML, but then finds problems with it, I'm guessing because it's Microsoft-flavored XML.

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    @yayikes As I mentioned, we're happy to take a look, but without seeing the problem it'll be hard to resolve. Could you link to a test case, please, instructions are in my message above.

    Colin

This discussion has been closed.