Null at the end of the JSon

Null at the end of the JSon

GrunardGrunard Posts: 2Questions: 1Answers: 0

I'm using Ajax to get a Json from a class in PHP but when I get the result it always comes with a null at the end of this.
For example

-[{"checkbox":"Prueba","internal_id":"Prueba","id_invoice":"Prueba","type":"Prueba","billing_period":"Prueba","invoice_date":"02\/09\/2016","due_date":"Prueba","payment_date":"Prueba","customer_id":"Prueba","customer_name":"Prueba","total_invoice":"Prueba","visible":"Prueba"}]null

My datatable code is:

`$('#invoices').dataTable( {
"paging": false,
"info": false,
"processing": true,
"bFilter": false,
"destroy" : true,
"ajax": {
"url": "/invoices/filter_invoices",
"dataSrc":'',
"type":"POST",
"data": {
"billingperiod": "N-N",
"invoicedate": '',
"duedate": '',
"paymentdate": '',
"invoicedateF": '',
"duedateF": '',
"paymentdateF": '',
"type": '0',
"searchcustomer": '0000/0000',
"bycustomer": '4'
}
},
"columns": [
{ "data": "checkbox" },
{ "data": "id_invoice" },
{ "data": "type" },
{ "data": "billing_period" },
{ "data": "invoice_date" },
{ "data": "due_date" },
{ "data": "payment_date" },

                                        { "data": "customer_name" },
                                        { "data": "total_invoice","type": "num"},
                                        { "data": "visible" },
                                        { "data": "internal_id" },
                                        { "data": "customer_id" },
                                   ]
                               } );`

Thanks in advance

This question has accepted answers - jump to:

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17

    The null is generated in your PHP code. So you have to look there. Before you send an "echo json_encode" place a "print_r(what-you-wished-to-send"); in your PHP to see what is happening.

  • GrunardGrunard Posts: 2Questions: 1Answers: 0

    the result of print_r() is
    Array ( [0] => Array ( [checkbox] => Prueba [internal_id] => Prueba [id_invoice] => Prueba [type] => Prueba [billing_period] => Prueba [invoice_date] => 02/09/2016 [due_date] => Prueba [payment_date] => Prueba [customer_id] => Prueba [customer_name] => Prueba [total_invoice] => Prueba [visible] => Prueba ) )

    Don´t have null.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    The null isn't in the JSON object as such, which suggests that it wouldn't be shown by the print_r() statement. There is likely an echo or print or something like that somewhere else in the PHP that is output that null independently.

    Allan

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    The null isn't in the JSON object as such, which suggests that it wouldn't be shown by the print_r() statement. There is likely an echo or print or something like that somewhere else in the PHP that is output that null independently.

    Allan

This discussion has been closed.