我想瘋狂嘗試弄清楚如何在用戶選擇選擇選項後在div標籤中顯示錶格。使用jQuery/AJAX從PHP返回html表格
的JQuery/AJAX
$('#months').change(function() {
var month_sent = $('#months option:selected').text();
$.ajax ({
type: "GET",
dataType: 'text',
url: "db_connect.php",
data: "dept_sent=" + dept_sent + "&month_sent=" + month_sent + "&year_sent=" + year_sent,
success: function(data) {
$('#incident_table').html(data);
},
error: function() {
alert("Error!");
}
});
});
PHP
if ($dept && year && $month) {
$query = "SELECT date,dept,area_name,ticket,description,resolution FROM incidents WHERE (dept = '$dept') AND (YEAR(date) = '$year') AND (MONTH(date) = '$month')";
$query_image = "SELECT image_content FROM images WHERE dept_name = '$dept' AND year = '$year' AND month = '$month'";
$result = mysql_query($query);
$result_image = mysql_query($query_image);
while ($row = mysql_fetch_assoc($result)) {
// foreach ($row as $value) {
$incident .= '<tr><td>'.$row['date'].'</td><td>'.$row['dept'].'</td><td>'.$row['area_name'].'</td><td>'.$row['ticket'].'</td><td>'.$row['description'].'</td><td>'.$row['resolution'].'</td></tr>';
//}
}
echo $incident;
}
所有我需要做的是能夠顯示錶中的 「事件」 的內部div標籤
編輯:
<div style="border: 1px solid black; width:310px; height: 310px;" name="incidents" id="incidents">
<table id="incident_table">
</table>
</div>
請他LP! :(
PHP端是否返回預期的輸出? – MrCode 2012-04-26 16:48:15
你的問題是什麼? – Madbreaks 2012-04-26 16:51:43
echo'