I have a page that generates a table and its content will be retrieved using .getJSON
. But i have a variable to be passed for that conditional query. Here is my code,
<?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>
how do i post var custid = '<?php echo $cust_id; ?>';
var custid = '<?php echo $cust_id; ?>';
to price_history_data.php
that contains the query so that the data inside the table only shows data based on the custid
variable that i send.. ?
Thanks again for the help
Here you are:
$.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;
});
Pass custid
as a get parameter in the 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.