Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81971

Json format for dataTables

$
0
0

Sorry if doubles posted....
I am using NSBasic which implements dataTables.

I am struggling to understand how to get data from MYSQL into the dataTable.

I think it is a formatting issues.

Test at http://www.toolfolks.com/AjaxPost/
I use the following PHP to get the results ( working okay )

$query5 = "SELECT invoice_no, product_name, delivery_status,pin_code ";  //intensionaly * to fetch all columns
$query5.=" FROM order_product";


if ($result = mysqli_query($mysqli, $query5)) {
  $out = array();

  while ($row = $result->fetch_assoc()) {
    //$out[] = $row;
    $out[] = $row['invoice_no'];
    $out[] = $row['product_name'];
    $out[] = $row['delivery_status'];
    //$out[] =  "]";
    //$out[] = $row['pin_code'];
  }
}
  /* encode array as json and output it for the ajax script*/
  echo json_encode($out);
  //var_dump($result);

I am using the following code:

```

Button1.onclick=function(){
req = Ajax("http://www.toolfolks.com/techy/someData.php", "GET", txtSend.value, done);
}
function done() {
if (req.status == 200) { //success
alert('data back');
htmResponse.innerHTML = req.responseText;
console.log('This is the data'+req.responseText);
// add to grid
var table = $("#DataTable1").DataTable();
table.clear();
var dataJson2 = JSON.stringify(htmResponse.innerHTML);
DataTable1.settings.data = req.responseText ;//JSON.parse(dataJson2);
setTimeout(loadTable, 50);
}
else {//'failure
htmResponse.innerHTML=req.err;
}
}
function loadTable() {
var table = $("#DataTable1").DataTable();
table.rows.add(DataTable1.settings.data).draw();
}
Button1Copy.onclick=function(){
$('#DataTable1').DataTable( {
"ajax": 'http://www.toolfolks.com/techy/someData.php'
} );
}

'''

Any help appreciated.
Be gentle with me as this is all new and 'brain hurty' time.
Cheers

Steve Warby


Viewing all articles
Browse latest Browse all 81971

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>