目的加載到PHP的HTML表格通過jQuery的.load調用
我想創建一個網頁從我database.The頁面上刪除記錄將包括一個用於填充其本身在頁面load.Upon從中選擇一個值並點擊提交按鈕,一個php頁面將被調用,並且php的結果將被加載到一個下面的表格中。然後,我可以點擊刪除按鈕,該按鈕將被旁邊的值回顯以刪除從數據庫中值
我的表格:
<!DOCTYPE HTML>
<html>
<head>
<!--Loads JQuery script-->
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<!--Gets list of item categories on page load-->
<script type="text/javascript">
$(document).ready(function(){
$("#viewsubcat").load("getcategory.php");
});
</script>
<script type="text/javascript">
$("#viewsubcatsubmit").click(function(){
var cat=$('#viewsubcat').val();
$('#deletetable').load('delsubcategory.php?cat='+cat);
});
</script>
</head>
<body>
<form style="width:500px" id="viewsubcategory" name="viewsubcategory" method="post" action="<? php echo $_SERVER['PHP_SELF'] ?>" >
<div class="inputfield">
<label for="viewsubcat">Select Category:</label>
<select style="margin-left:37px" id="viewsubcat" name="viewsubcat"></select>
</div><br />
<div class="inputfield">
<input style="margin-left:250px" type="button" id="viewsubcatsubmit" name="viewsubcatsubmit" value="Search" /></div>
</div><br />
</form>
<table id="deletetable">
</table>
</body>
</html>
PHP頁面:
<?php
include("cxn.inc");
$id=$_SESSION['BizID'];
$cat=$_GET['cat'];
$viewsubcat=$cxn->prepare("SELECT * FROM `itemcat`,`itemsubcat`
WHERE `itemcat`.`CatID`=:cat AND `itemsubcat`.`ItemCat`=:cat AND `itemsubcat`.`BusinessID`=:id");
$viewsubcat->bindValue(":cat",$cat);
$viewsubcat->bindValue(":id",$id);
$viewsubcat->execute();
//echo"<table border='1'>";
echo"<tr>";
echo"<td>";
echo"Categories";
echo"</td>";
echo"<td>";
echo"SubCategories";
echo"</td>";
echo"<td>";
echo"Action";
echo"</td>";
echo"</tr>";
while($getsubcat=$viewsubcat->fetch(PDO::FETCH_ASSOC))
{
$cat=$getsubcat['ItemCat'];
$subcat=$getsubcat['ItemSubCat'];
$subcatid=$getsubcat['SubCatID'];
echo"<tr>";
echo"<td>";
echo"$cat";
echo"</td>";
echo"<td>";
echo"$subcat";
echo"</td>";
echo"<td>";
echo"<form id='delsubcategory' name='delsubcategory' method='POST' action='delsubcategory.php'>";
echo"<input type='hidden' id='delsubcatid' name='delsubcatid' value='$subcatid' />";
echo"<input type='submit' id='delsubcatsubmit' name='delsubcatsubmit' value='Delete' />";
echo"</form>";
echo"</td>";
echo"</tr>";
}
//echo"</table>";
?>
問題:
HTML表沒有加載在按壓button.The PHP的頁面工作時我改變形式的行動 「delsubcategory.php」和按鈕類型=「提交」,所以問題在於html。
希望得到任何見解此事
你得到一個錯誤? – Rab
@RabNawaz Dipesh明白了。我忘了把我的.click換成$(function()); –