0

I have a question here.

I have a page for displaying data from my database. I use ajax for handler the data I get.

In my other page I can use this method for displaying data. I am not getting an error massage and the data displaying well. I have check my code and I think there is no error syntax in there.

But why? In this page my code can't get the data and I get this error massage. is this because my library not support for that or have I crashed in my library?

1st. this is the error massage:

The Error Massage that i get

and in my html page I use this library.

<script type="text/javascript" src="../jquery/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-1.12.4.js"></script>
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript" src="../jquery/jquery.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.js"></script>

and the last this is my code for display the data.

The code for get the data and display the data into the table.

$(document).on('click','#display_data',function(e) {
 var data = $("#report_all").serialize();
   
 $('#all_report tbody').empty();
        $.ajax({
   data: data,
            type: "Post",
            url: "../php/report/report_all_KA.php",
            success: function(data){
     var list = JSON.parse(data);
     var th = "";
  
        th += "<th>" +'Tanggal'+"</th>";
        th += "<th>" +'Type Kadar Air'+"</th>";
        th += "<th>" +'Kode Material'+"</th>";
        th += "<th>" +'Nama Material'+"</th>";
        th += "<th>" +'Storage Location'+"</th>";
        th += "<th>" +'Kadar Air'+"</th>";
        th += "<th>" +'Nama PPIC'+"</th>";
 
  th += "</th>";
  $("#all_report thead").append(th);
  for(var i = 0; i < list.length; i++){
  
  var tr = "<tr>";
  
        tr += "<td>" +list[i]['date']+"</td>";
        tr += "<td>" +list[i]['type']+"</td>";
        tr += "<td>" +list[i]['kode']+"</td>";
        tr += "<td>" +list[i]['nama']+"</td>";
        tr += "<td>" +list[i]['sloc']+"</td>";
        tr += "<td>" +list[i]['ka']+"</td>";
        tr += "<td>" +list[i]['ppic']+"</td>";
 
  tr += "</tr>";
 
    $("#all_report tbody").append(tr);
 $("#all_report").show();
  }
  return false;
 
 
}
});
});

The PHP code

<?php
include("../../Connections/koneksi.php");
$date_start=$_POST['date_start'];
$date_end=$_POST['date_end'];
$kode_mat=$_POST['kode_mat'];
$sloc=$_POST['sloc'];
$type=$_POST['get_type'];
$order=$_POST['order'];

if (empty($date_start) || empty($date_end) || empty($kode_mat) || empty($sloc) || empty($type) || empty($order)) {
    // Data for Titik1
$sql = "SELECT * FROM kadar_air";
$query = mysqli_query($db,$sql);
$rows = array();

while($tmp= mysqli_fetch_array($query)) {
    $rows[] = $tmp;
}

echo json_encode($rows);
mysqli_close($db);

}
else {
  
}

?> 

And the Html Code for the Table

 <table id="all_report" class='table table-bordered'>
  <thead></thead>
  <tbody></tbody>
 </table>
 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Minervaz Mine
  • 273
  • 1
  • 3
  • 17
  • 3
    check your JSON response – tech2017 Aug 21 '17 at 19:10
  • @tech2017 how i can check it? use alert ? – Minervaz Mine Aug 21 '17 at 19:11
  • check under `Network` tab in inspector, click on the link to see results. – tech2017 Aug 21 '17 at 19:12
  • i am not get anything in there – Minervaz Mine Aug 21 '17 at 19:15
  • 2
    why have you included so many versions of jQuery? – Tom O. Aug 21 '17 at 19:15
  • last time i just put 2 jquery in there. but i think my friend put more T_T because of that i asking this thing. maybe its because the jquery crash or something – Minervaz Mine Aug 21 '17 at 19:18
  • 1
    btw... i solve it. it just because the code in my php `if (empty($date_start) || empty($date_end) || empty($kode_mat) || empty($sloc) || empty($type) || empty($order)) {` because of this maybe. i try to delete that line i can display the data. – Minervaz Mine Aug 21 '17 at 19:19
  • This might not have anything to do with your issue, but you should be careful when adding libraries like that because it can cause conflicts between them. [Check out this question for more info on that](https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page). The answer will show you how to avoid conflicts if multiple versions of jQuery are required. – Tom O. Aug 21 '17 at 19:19
  • nah.. like i said @TommyO last time i just put 2 jquery only. my friend has edited that – Minervaz Mine Aug 21 '17 at 19:20
  • btw ... why this like make my data can't be loaded? `if (empty($date_start) || empty($date_end) || empty($kode_mat) || empty($sloc) || empty($type) || empty($order)) {`? – Minervaz Mine Aug 21 '17 at 19:21
  • You could load the page in browser as well for checking. Something like `http://localhost//php/report/report_all_KA.php` And it would be a good idea to send the data from your php script with a json header `header('Content-Type: application/json');` – Nirmi Aug 21 '17 at 20:21
  • @Livingstone i didn't get you.. this problem now has solve but i need to clear a line from my `php` code like this `if (empty($date_start) || empty($date_end) || empty($kode_mat) || empty($sloc) || empty($type) || empty($order)) ` nah.. i want to know why i must clear that line just for getting the data? – Minervaz Mine Aug 21 '17 at 20:37
  • What else do you have in your `else ` , the problem is, that there is no data for json in the `else` case. – Nirmi Aug 22 '17 at 07:33
  • @Livingstone its because of that? the data can't be parse? just because i don't have else case in there? – Minervaz Mine Aug 22 '17 at 15:59
  • @MinervazMine for the case when everything is not empty the `else` hits and then you have no output and a empty response is not a valid json. – Nirmi Aug 22 '17 at 19:51
  • Oh..ok" i know the case now. Th. For the explantion @Livingstone – Minervaz Mine Aug 23 '17 at 05:54

0 Answers0