双击 td 时,如何在警告框中将数据库中的数据显示为 html 表

How to show the data from database in a alert box as html table when td is double clicked

本文关键字:数据库 数据 显示 html td 警告 双击      更新时间:2023-09-26

我正在尝试在 HTML 表中显示数据库中的数据,我想在双击td时在警报框中显示此 html 表,现在当双击td时,它在警报框中显示数据,但不像 html 表那样显示(注意: 现在它在警报框中显示数据,但不显示为 HTML 格式),下面是我的代码。

阿贾克斯

$('td').dblclick(function() {                
      $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "supplierprice/retrieve.php",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $("#responsecontainer").html(response); 
          alert(response);
        }
    });
});

.HTML

echo '  <td id="alertShow" width="114px;" class="edit region '.$rows["supp_price_id"].'">'.$rows["region"].'</td>
        <td id="alertShow" width="115px;" class="edit country '.$rows["supp_price_id"].'">'.$rows["country"].'</td>
        <td id="alertShow" width="286px;" class="edit networkname '.$rows["supp_price_id"].'">'.$rows["networkname"].'</td>
        <td id="alertShow" width="92px;"  class="edit mcc '.$rows["supp_price_id"].'">'.$rows["mcc"].'</td>  
        <td id="alertShow" width="94px;"  class="edit mnc '.$rows["supp_price_id"].'">'.$rows["mnc"].'</td>
        <td id="alertShow" width="92px;" class="edit mnp '.$rows["supp_price_id"].'">'.$rows["mnp"].'</td>';

检索.php

include"config.php";
$result=mysql_query("select * from supplierpricehistory");
echo "<table border='1' >
<tr>
<td align=center> <b>supplier</b></td>
<td align=center><b>country</b></td>
<td align=center><b>networkname</b></td>
<td align=center><b>mcc</b></td></td>
<td align=center><b>mnc</b></td>
<td align=center><b>newprice</b></td>       
<td align=center><b>oldprice</b></td>       
<td align=center><b>status</b></td>     
<td align=center><b>date</b></td>           
<td align=center><b>user</b></td>";
while($data = mysql_fetch_row($result))
{   
    echo "<tr>";
    echo "<td align=center>$data[1]</td>";
    echo "<td align=center>$data[2]</td>";
    echo "<td align=center>$data[3]</td>";
    echo "<td align=center>$data[4]</td>";
    echo "<td align=center>$data[5]</td>";
    echo "<td align=center>$data[6]</td>";
    echo "<td align=center>$data[7]</td>";
    echo "<td align=center>$data[8]</td>";
    echo "<td align=center>$data[9]</td>";
    echo "<td align=center>$data[10]</td>";
    echo "</tr>";
}
echo "</table>";

谁能指导我如何做到这一点,或者还有其他方法可以做到这一点。谢谢

标准 js 警报无法格式化。例如,您应该使用自定义对话框 http://jqueryui.com/dialog/