使用 ajax、sql 和 php 发出 html 警报
Making a html alert using ajax, sql and php
我正在尝试制作一些代码,其中单击 SQL html 按钮可以显示不同的 SQL table 作为弹出窗口。我已经从 table 中获取变量以使用此方法传递:
echo "<td><a class='btn-floating btn-large waves-effect waves-light black' onclick='partSearch(".$product.")' value='display'><i class='material-icons'>search</i></a></td>";
'part search'代码如下:
<script type="text/javascript">
function partSearch() {
$.ajax({
url: 'serv.php?id=<?php echo $product ?>',
type: 'GET',
success: function(result){
var obj = jQuery.parseJSON(result)
alert(obj)
}
})
}
</script>
即使变量传递给 'serv.php',我也无法使用警报将 sql 数据作为弹出窗口返回。我得到的要么什么都没有,要么是 [object, Object]。这是 SQL/php 代码:
<?php
include 'includes/dbh.inc.php';
$id = $_GET['id'];
$result = mysqli_query($conn,"SELECT * FROM pr WHERE product_ID='".$id."'");// test this
$rows = array();
while($r = mysqli_fetch_assoc($result)){
$rows[] = $r;
}
echo json_encode($rows);
?>
任何帮助都适用
<script type="text/javascript">
function partSearch() {
var product_id = "<?php echo $product; ?>";
$.ajax({
url: 'serv.php?id=product_id',
type: 'GET',
success: function(result){
alert(result);
}
})
}
</script>
我正在尝试制作一些代码,其中单击 SQL html 按钮可以显示不同的 SQL table 作为弹出窗口。我已经从 table 中获取变量以使用此方法传递:
echo "<td><a class='btn-floating btn-large waves-effect waves-light black' onclick='partSearch(".$product.")' value='display'><i class='material-icons'>search</i></a></td>";
'part search'代码如下:
<script type="text/javascript">
function partSearch() {
$.ajax({
url: 'serv.php?id=<?php echo $product ?>',
type: 'GET',
success: function(result){
var obj = jQuery.parseJSON(result)
alert(obj)
}
})
}
</script>
即使变量传递给 'serv.php',我也无法使用警报将 sql 数据作为弹出窗口返回。我得到的要么什么都没有,要么是 [object, Object]。这是 SQL/php 代码:
<?php
include 'includes/dbh.inc.php';
$id = $_GET['id'];
$result = mysqli_query($conn,"SELECT * FROM pr WHERE product_ID='".$id."'");// test this
$rows = array();
while($r = mysqli_fetch_assoc($result)){
$rows[] = $r;
}
echo json_encode($rows);
?>
任何帮助都适用
<script type="text/javascript">
function partSearch() {
var product_id = "<?php echo $product; ?>";
$.ajax({
url: 'serv.php?id=product_id',
type: 'GET',
success: function(result){
alert(result);
}
})
}
</script>