Я попытался использовать datatables, потому что это просто, но теперь у меня проблема с перезагрузкой и получением новых данных в datatables из запроса ajax после щелчка.для более подробной информации, это мой скрипт под ним:
index.html
<html>
<head>
<title>Datatables</title>
<link rel="stylesheet" type="text/css" href="../plugins/DataTables/styles.css"/>
<script type="text/javascript" src="../plugins/DataTables/datatables.min.js"></script>
<script type="text/javascript" src="../plugins/DataTables/javascript.js"></script>
<script src="../lib/js/jquery/jquery.min.js"></script>
</head>
<body>
<table id="tablenya" class="datatable responsive nowrap" style="width:100%">
<thead>
<tr>
<th>No</th>
<th>PO Date</th>
<th>WO No</th>
<th>PO No</th>
<th>Customer</th>
<th>Size</th>
<th>Status</th>
<th>Option</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
javascript.js
$(document).ready(function(){
var tablenya = $('#tablenya').dataTable({
"ajax": "process.php?action=result",
"columns": [
{ "data": "no" },
{ "data": "date_po" },
{ "data": "no_spk"},
{ "data": "no_po" },
{ "data": "customer"},
{ "data": "size"},
{ "data": "status"},
{ "data": "functions","sClass": "functions" }
]
});
});
и затем раздел process.php для получения моих данныхв базе данных
<?php
require 'connect.php';
$action = '';
$id = '';
if(isset($_GET['action'])){
$action = $_GET['action'];
if($action == 'result'){
if (isset($_GET['id'])){
$id = $_GET['id'];
if (!is_numeric($id)){
$id = '';
}
}
} else {
$action = '';
}
}
$mysqli_data = array();
if ($action == 'result'){
$query = "SELECT * FROM workorder WHERE status='1' ORDER BY id DESC";
$sql = $connect->query($query);
if (!$sql){
$result = 'error';
$message = 'query error';
} else {
$result = 'success';
$message = 'query success';
$no = 1;
while($row = $sql->fetch_array()){
$functions = '<div class="function_buttons"><ul>';
$functions .= '<li class="function_view"><a data-id="'.$row['id'].'" data-name="'.$row[$dataName].'" title="View details"><span>View details</span></a></li>';
$functions .= '</ul></div>';
$mysqli_data[] = array(
"no" => $no++,
"date_po" => $row['date_po'],
"no_spk" => $row['no_spk'],
"no_po" => $row['no_po'],
"customer" => $row['customer'],
"size" => $row['size'],
"status" => $status,
"functions" => $functions
);
}
}
}
mysqli_close($connect);
$data = array(
"result" => $result,
"message" => $message,
"data" => $mysqli_data
);
$json_data = json_encode($data);
print $json_data;
?>
после загрузки страницы "index.html" мои данные сгенерированы с помощью datatables.посмотрите «Просмотр функции» в опции столбца, и я хочу создать другую функцию с щелчком мыши, чтобы показать данные из другой таблицы в базе данных на основе значения «data-id =» с запросом ajax, под ним:
javascript.js раздел onclick function
$(document).ready(function(){
$(document).on('click', .function_view a, function(e){
e.preventDefault();
var id = $(this).data('id');
var request = $.ajax({
url: "another.php?action=result",
cache: false,
data: 'id='+id,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'get'
});
request.done(function(output){
if (output.result == success){
/////////////////////////////////////////
// reload datatables and showing new request
////////////////////////////////////////
} else {
show_message('Information request failed', 'error');
}
});
request.fail(function(jqXHR, textStatus){
show_message('Information request failed: '+textStatus, 'error');
});
});
});
это еще один раздел .php
<?php
require 'connect.php';
$action = '';
$id = '';
if(isset($_GET['action'])){
$action = $_GET['action'];
if($action == 'result'){
if (isset($_GET['id'])){
$id = $_GET['id'];
if (!is_numeric($id)){
$id = '';
}
}
} else {
$action = '';
}
}
$mysqli_data = array();
if($action == 'result'){
if ($id == ''){
$result = 'erro';
$message = 'ID missing';
} else {
$idx = mysqli_real_escape_string($connect, $id);
$query = "SELECT * FROM workorder LEFT JOIN workorder_process ON workorder.id_fk = workorder_process.id_fk WHERE workorder.id = '".$idx."'";
$sql = $connect->query($query);
$get = $sql->fetch_array();
if($get['delivery_type'] == '2'){
$result = 'success';
$message = 'query success';
$no = 1;
while($row = $sql->fetch_array()){
$functions = '<div class="function_buttons"><ul>';
$functions .= '<li class="function_edit"><a data-id="'.$row['id'].'" data-name="'.$row[$dataName].'" title="Edit"><span>Edit</span></a></li>';
$functions .= '</ul></div>';
$mysqli_data[] = array(
"no" => $no++,
"date_po" => $row['date_po'],
"date_spk" => $row['date_spk'],
"no_spk" => $row['no_spk'],
"no_po" => $row['no_po'],
"customer" => $row['customer'],
"size" => $row['size'],
"qore" => $row['qore'],
"roll" => $row['roll'],
"material" => $row['material'],
"ingredient" => $row['ingredient'],
"send_qty" => $row['send_qty'],
"volume" => $row['volume'],
"annotation" => $row['annotation'],
"functions" => $functions
);
}
} else {
$result = 'error';
$message = 'ID missing';
}
}
}
mysqli_close($connect);
$data = array(
"result" => $result,
"message" => $message,
"data" => $mysqli_data
);
$json_data = json_encode($data);
print $json_data;
?>
Итак, как перезагрузить и получить новые данные после нажатия «представление функции» с помощью запроса ajax?в строке комментария javascript.js
// перезагружаем таблицы данных и показываем новый запрос
это возможно?пожалуйста, дайте мне совет