gpt4 book ai didi

javascript - 使用 .getJSON 为条件 SQL 查询传递变量

转载 作者:行者123 更新时间:2023-11-30 16:30:04 25 4
gpt4 key购买 nike

我有一个生成表格的页面,其内容将使用 .getJSON 检索.但是我要为该条件查询传递一个变量。这是我的代码,

<?php $cust_id = $_GET['cust_id']; ?>
<table class="display" id="invoice-disc-list" cellspacing="0" width="100%">
<thead>
<tr>
<th>INVOICE #</th>
<th>INVOICE DATE</th>
<th>SALESMAN</th>
<th>INVOICE AMOUNT</th>
<th>DISCOUNT</th>
</tr>
</thead>
</table>

<script>
$.getJSON('pages/lj_menu/monitoring/process/price_history_data.php', function(response) {
var custid = '<?php echo $cust_id; ?>';
// Initialize DataTables
$('#invoice-disc-list').DataTable({
iDisplayLength : 15,
processing: true,
data: response,
columns: [
{data: "INVOICE_NO"},
{data: "INVOICE_DATE"},
{data: "INVOICE_SALESMAN"},
{data: "INVOICE_AMOUNT"},
{data: "INVOICE_DISCOUNT"}
]
});

// Initialize AJAX onClick Data Send
window.someGlobalOrWhatever = response.balance;
});
</script>

我如何发布var custid = '<?php echo $cust_id; ?>';price_history_data.php包含查询,以便表内的数据仅显示基于 custid 的数据我发送的变量.. ?

再次感谢您的帮助

最佳答案

custid 作为 URL 中的获取参数传递

<?php $cust_id = $_GET['cust_id']; ?>
<table class="display" id="invoice-disc-list" cellspacing="0" width="100%">
<thead>
<tr>
<th>INVOICE #</th>
<th>INVOICE DATE</th>
<th>SALESMAN</th>
<th>INVOICE AMOUNT</th>
<th>DISCOUNT</th>
</tr>
</thead>
</table>

<script>
$.getJSON('pages/lj_menu/monitoring/process/price_history_data.php?custid=<?php echo $cust_id; ?>', function(response) {
var custid = '<?php echo $cust_id; ?>';
// Initialize DataTables
$('#invoice-disc-list').DataTable({
iDisplayLength : 15,
processing: true,
data: response,
columns: [
{data: "INVOICE_NO"},
{data: "INVOICE_DATE"},
{data: "INVOICE_SALESMAN"},
{data: "INVOICE_AMOUNT"},
{data: "INVOICE_DISCOUNT"}
]
});

// Initialize AJAX onClick Data Send
window.someGlobalOrWhatever = response.balance;
});
</script>

关于javascript - 使用 .getJSON 为条件 SQL 查询传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33441780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com