我有数据表json name = table_a.php 我有该文件的超链接..
我可以显示数据表
<table data-url="table_a.php"></table>
该列上的有超链接。我想处理到ajax的链接。
<script>
$(document).ready(function() {
//$(document).on("click", "#stats", function (e) {
$('#stats').click(function(e) {
alert("a");
e.preventDefault();
$.ajax({
alert("ab");
url: 'update_process.php',
data: $(this).serialize(),
dataType: 'json',
success: function(status) {
var datanya = JSON.parse(JSON.stringify(status));
$('#table').bootstrapTable('refresh', {url: 'table_a.php'});
}
});
return false;
});
})
</script>
我尝试点击链接,但警报从不显示。
table_a.php:
<?php
header('content-type:application/json');
include '../koneksi.php';
$select = mysql_query("select * from tb_pemesanan where no_meja='$_GET[meja]'");
$row=array();
while($row=mysql_fetch_array($select))
{
$select1 = mysql_query("SELECT * FROM tb_pemesanan where id_pemesanan='$row[id_pemesanan]' AND status='Sedang di proses'");
$status='0';
if(mysql_num_rows($select1)== 0) {
$status="<a class='btn btn-success' href='#'><b>Sudah di antar <span class='glyphicon glyphicon-ok'></span></b></a>";
}else{
$status="<a id='stats' class='btn btn-primary' href='proses.php'>
<b>Sedang di proses <span class='glyphicon glyphicon-hourglass'></span></b></a>";
}
$arrayx=array( "status"=>$status );
$rows[] = $arrayx;
}
echo json_encode($rows);
?>
答案 0 :(得分:0)
尝试更新您的table_a.php
代码,如下所示。您可以找到一些评论,说明我在该计划中所做的更改及其原因。
<?php
header('content-type:application/json');
include '../koneksi.php';
$select = mysql_query("SELECT * FROM tb_pemesanan WHERE no_meja = '$_GET[meja]'");
$row = array();
while($row = mysql_fetch_array($select)) {
$select1 = mysql_query("SELECT * FROM tb_pemesanan WHERE id_pemesanan = '$row[id_pemesanan]' AND status = 'Sedang di proses'");
$status = '0';
if(mysql_num_rows($select1) == 0) {
$status = "<a class='btn btn-success' href='#'><b>Sudah di antar <span class='glyphicon glyphicon-ok'></span></b></a>";
} else {
// id = "stats" changed to class="stats"
$status = "<a class='btn btn-primary stats' href='proses.php'>
<b>Sedang di proses <span class='glyphicon glyphicon-hourglass'></span></b></a>";
}
$arrayx = array("status"=>$status);
$rows[] = $arrayx;
}
echo json_encode($rows);
?>
同时更改javascript
:
<script>
$(document).ready(function() {
// $(document).on("click", "#stats", function (e) {
// jquery counts only first id, so if you want to apply the same for all buttons you should change that id to class name
$('.stats').click(function(e) {
alert("a");
e.preventDefault();
$.ajax({
alert("ab");
url: 'update_process.php',
data: $(this).serialize(),
dataType: 'json',
success: function(status) {
var datanya = JSON.parse(JSON.stringify(status));
$('#table').bootstrapTable('refresh', {url: 'table_a.php'});
}
});
return false;
});
})
</script>
试试吧。如果它仍然没有提供正确的输出,请输入我的PHP脚本输出。