How do I fix the unknown parameter error with Datatables popuated by a php file and json data format

How do I fix the unknown parameter error with Datatables popuated by a php file and json data format

malaikamalaika Posts: 1Questions: 1Answers: 0

I want to populate the datatable with data from mysql ,using a php file and json data format. But I get an error that says table unable to access parameter for row 0 column 0.

This is the html table
'

Name
Name

'
this is the jquery code with ajax.
'$( document ).ready(function() {
$.ajax({
url:'./process.php',
method:'post',
datatype:'json',
data:{action:'action'},
beforeSend: function(){
alert("testing");
},
success:function(data){
$('#example').dataTable({
data:data,
columns:[
{'data':'first_name'}
]
});
}
});

});
'

this is the code from the php file.
' <?PHP

if(isset($_POST['action'])) {

include_once 'includes/psl-config.php';
include_once 'includes/db_connect.php';

$json = array();
try{

$stmt = $dbh->prepare("SELECT first_name FROM data_centre_users ");
if(!$stmt->execute())return false;
// output data of each row

            if($stmt->rowCount() > 0){

            while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ 
                $json['data'][] = $rows;
            }
        // $json['success']= true;              

         echo json_encode($json);

        }

}catch(PDOeception $e;)
{echo " Error ".$e->getMessage();}

}

<?php > ' ?>

Answers

  • allanallan Posts: 63,784Questions: 1Answers: 10,511 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • allanallan Posts: 63,784Questions: 1Answers: 10,511 Site admin

    p.s. I've deleted your duplicate discussion with exactly the same text. There aren't many forum rules, please follow them and I'd be happy to help.

This discussion has been closed.