[英]select data from database using jquery doesn't get the value
hi guys i've a problem here i made a project and in that project have a function for calling data from database for displaying in the table. 嗨,大家好,我在这里有一个问题,我做了一个项目,在那个项目中有一个功能,可以从数据库中调用数据以显示在表中。 i've check the php function but it running well.
我已经检查了PHP功能,但它运行良好。 i've thinking i've an eror at my jquery but i dont know where the eror and how to fix it.
我想我在我的jquery上有一个错误,但我不知道错误在哪里以及如何解决。 please help me i hope anyone can solve my problem and give any correction on my code
请帮助我,我希望任何人都可以解决我的问题,并对我的代码进行任何更正
Here my code (JQUERY,PHP,HTML) 这是我的代码(JQUERY,PHP,HTML)
$(document).on('click','#show',function(e) {
var data = $("#form_input4").serialize();
$('#table_1 tbody').empty();
$.ajax({
data: data,
type: "Post",
url: "../php/bkk_1/bkk_show.php",
success: function(data){
var list = JSON.parse(data);
for(var i = 0; i < list.length; i++){
$('#mat').val((list[i]['material']));
$('#lok').val((list[i]['lokasi']));
$('#kpl').val((list[i]['kapal']));
$('#po_numb').val((list[i]['po']));
$('#date').val((list[i]['tanggal']));
var tr = "<tr>";
tr += "<td>" +list[i]['no']+"</td>";
tr += "<td>" +list[i]['no_pol']+"</td>";
tr += "<td>" +list[i]['netto']+"</td>";
tr += "</tr>";
$("#table_1 tbody").append(tr);
}
return false;
}
});
});
<?php
$con=mysqli_connect("localhost","root","","silo");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$tgl=$_POST['tgl'];
$po=$_POST['no_po'];
// Data for Titik1
$query = mysqli_query($con,"SELECT * FROM bkk_1 WHERE tanggal='$tgl' and po='$po' LIMIT 0, 38");
$rows = array();
while($tmp= mysqli_fetch_assoc($query)) {
$rows[] = $tmp;
}
echo json_encode($rows);
mysqli_close($con);
?>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<div id="content1" class="btn btn-default">
<p align="center" <strong>Display Data Pada Kondisi: </p></strong>
<div id="content1" class="btn btn-default">
<form action="../php/bkk_1/bkk_show.php" id="form_display" method="post">
<table>
<tr>
<td width="50">Tanggal </td>
<td width="10">:</td>
<td width="30"><input type="text" id="tgl" type="text" name="tgl" size="15" /></td>
<td width="10"><img src="../image/show.png" class="show" name="display" id="display" style="height:35px; width: 40px; padding: 5px 5px; font-size: 24px; text-align: center; cursor: pointer; outline: none; color: #fff;
background-color: #ffff; border: none; border-radius: 10px; box-shadow: 0 2px #000000;" /></td>
</tr>
<tr>
<td width="50">PO Number </td>
<td width="10">:</td>
<td width="30"><input type="text" id="no_po" type="text" name="no_po" size="15" /></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
Your form doesn't have the id="form_input4"
which is what you are serializing into your data variable and POSTing to your PHP. 您的表单没有
id="form_input4"
,这是您要序列化到数据变量中并过帐到PHP的内容。 Though I suspect what you want is var data = $("#form_display").serialize()
虽然我怀疑您想要的是
var data = $("#form_display").serialize()
Several things you can do to debug this: 您可以执行以下几项调试操作:
console.log($("#form_display").serialize());
to verify the data you are sending into your ajax is what you expect 验证发送到ajax中的数据是否符合您的期望
var_dump($_POST);
in your PHP file to see that your data is making it to the server in the way you expect 在您的PHP文件中,以查看您的数据是否以您期望的方式发送到服务器
var_dump($rows);
before you echo it to see if contains the data you expect 在回显它以查看是否包含您期望的数据之前
console.log(list)
inside your success callback function 成功回调函数中的
console.log(list)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.