Datatable cannot fetch from AJAX file
Datatable cannot fetch from AJAX file
naoki
Posts: 2Questions: 1Answers: 0
This is my ajax code:
<?php
include "db.php";
class classDetails {
public function classDetails(){
// create sql query
$viewClass = "SELECT class.id, class.day, class.start_time, class.end_time, subject.subject_name, tutor.tutor_id, tutor.tutor_name AS t_name, classroom.room
FROM class, subject, tutor, classroom
WHERE class.subject_id = subject.id
AND class.tutor_id = tutor.id
AND class.classroom_id = classroom.id";
return $this->query($viewClass);
}
}
and this is my datatable code:
<script type="text/javascript">
$(document).ready(function() {
//$.fn.dataTable.TableTools.defaults.aButtons = [ "csv" ];
$('.datatable').DataTable({
destroy: true,
responsive: true,
serverSide: true,
processing: true,
lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
ajax: {
url: "http://localhost/FYP/ajax.php/classDetails/",
type: "POST",
data: { method: "get" } //data to be sent
},
dom: 'T<"clear">lfrtip',
tableTools: {
"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
},
columns : [
{
data: "id",
render: function(data, row) {
return '<a href="http://localhost/FYP/viewClass' + row.id + '/">' + data + '</a>';
}
},
</script>
I am unable to call it out and I keep getting error tn1
This discussion has been closed.
Answers
Format your code properly first... The instructions are literally right under the "Post Comment" button.
ok I am done formatting the codes
It says it cant fetch from the ajax source?
What happens when you go right to http://localhost/FYP/ajax.php/classDetails/ in your browser, do you see the JSON that is expected?