我正在尝试使用日期类型获取有关日期更改的数据,从数据库中获取数据。但在此之后,获取的数据包含要单击的按钮。点击按钮再次获取数据。
这是代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<input type="date" name="gdate" id="gdate" onchange="<?php echo $_SERVER['PHP_SELF'] ?>"/>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function makeAjaxRequest(dateval) {
$.ajax({
type: "GET",
data: {dateva: dateval},
url: "fetchbills.php",
success: function (data) {
$('#showresult').html(data);
$('#det').on("click", function () {
var no = $(this).val();
makeAjaxRequest2(no);
});
}
});
}
function makeAjaxRequest2(billno) {
$.ajax({
type: "GET",
data: {bno: billno},
url: "fetchbilldetail.php",
success: function (data) {
$('#showresult').html(data);
}
});
}
$("#gdate").on("change", function () {
var id = $(this).val();
makeAjaxRequest(id);
});
</script>
<div id="showresult">
</div>
</body>
</html>
fetchbills.php
<?php
include("./config.php");
$dt = $_REQUEST["dateva"];
$sql = "select bill_id,order_id from bill_master where order_date='$dt'";
echo $sql;
$result = mysqli_query($con, $sql) or die("error");
if ($result) {
while ($row = mysqli_fetch_array($result)) {
echo $row[0] . "<br>";
echo "<form method='post' action=''><input type='submit' name='det' value='" . $row[1] . "' onclick='get(this.value)' /></form>
<div id='show'></div>";
}
}
?>
使用上面我得到的订单ID。身份证以按钮的形式显示。 点击按钮我想获得订单ID的详细信息。但是我做了什么sholud我无法理解。
我是ajax的新手,不知道该怎么做。
这里是订单详情的代码
<?php
include("./config.php");
$det = $_GET["bno"];
//echo $det;
$sql = "SELECT m.old_order_id,m.old_order_amount,l.item_id,l.old_order_quantity,i.item_name from old_order_master m,old_order_list l,item_list i where m.old_order_id=$det and m.old_order_id=l.old_order_id and l.item_id=i.item_id";
//echo $sql;
$result = mysqli_query($con, $sql);
echo "<table><tr><th>Item Name</th><th>Quantity</th></tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row[4] . "</td><td>" . $row[3] . "</td></tr>";
}
echo "</table>";
?>
答案 0 :(得分:1)
在 fetchbills.php
文件中进行以下更改,然后告诉我们
<?php
include("./config.php");
$dt = $_REQUEST["dateva"];
$sql = "select bill_id,order_id from bill_master where order_date='$dt'";
$result = mysqli_query($con, $sql) or die("error");
if ($result) {
while ($row = mysqli_fetch_array($result)) {
echo $row[0] . "<br>";
echo "<form method='post' action=''>"
."<input type='button' name='det' value='" . $row[1] . "' onclick='makeAjaxRequest2(".$row[1].");' /></form>"
."<div id='show'></div>";
}
}