我有2个输入日期
<form id="refresh" method="post" action="income.php">
<input type="text" id="dari" name="dari" />
<input type="text" id="sampai" name="sampai" />
<button type="submit">refresh</button>
</form>
和js:
<script>
$(document).ready(function() {
$('#dari').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
$('#sampai').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
});
</script>
那么如果我点击按钮,它只是刷新表,日期就会改变。这是我点击按钮时的ajax,它只是刷新数据表。还有日期范围更改,例如我在输入#dari
和#sampai
<script type="text/javascript">
$(document).ready(function() {
$('#refresh').submit(function() {
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: 'json',
success: function(status) {
var datanya = JSON.parse(JSON.stringify(status));
$('#income').bootstrapTable('refresh', {
url: '../../tables/income.php'
});
}
})
return false;
});
})
</script>
添加整个代码income.php
<?php
header('content-type:application/json');
include '../connetion.php';
$select=mysql_query("select nama_menu, qty, price, disc, tgl_transaksi from tb_transaksi where tgl_transaksi BETWEEN '$_POST[dari]' AND '$_POST[sampai]'");
$row=array();
while($row=mysql_fetch_array($select))
{
$arrayx=array( "nama_menu"=>$row['nama_menu'],
"qty"=>$row['qty'],
"price"=>$row['price'],
"disc"=>$row['disc']
);
$rows[] = $arrayx;
}
echo json_encode($rows);
?>
答案 0 :(得分:0)
您正在使用表单。如果您提交表单,它将刷新页面。而是将按钮类型设置为按钮并使用该按钮的单击事件。
<form id="refresh" method="post" action="income.php">
<input type="text" id="dari" name="dari" />
<input type="text" id="sampai" name="sampai" />
<button id='ref' type="button">refresh</button>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#ref').click(function() {
$.ajax({
type: 'POST',
url: $("#refresh").attr('action'),
data: $("#refresh").serialize(),
dataType: 'json',
success: function(status) {
var datanya = JSON.parse(JSON.stringify(status));
$('#income').bootstrapTable('refresh', {
url: '../../tables/income.php'
});
}
})
return false;
});
})
</script>