我有一个生成表格的页面,其内容将使用.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
变量的数据。?
再次感谢您的帮助
答案 0 :(得分:1)
你在这里:
$.getJSON('pages/lj_menu/monitoring/process/price_history_data.php', '<?php echo $cust_id; ?>')
.done(function(response) {
// 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;
});
答案 1 :(得分:1)
将custid
作为网址
<?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>