我试图从php中创建的表中删除动画行。
我是AJAX和JQuery的菜鸟,我似乎无法看到我出错的地方。 我也尝试按照我获得代码http://davidwalsh.name/animated-ajax-jquery的网站,但似乎发生的是当我点击删除链接时没有任何反应。
这是我的delete.php
// connect to the database $dbConn = odbc_connect("flamingo","","") or die("Error opening database .... use the browsers BACK button"); if (isset($_GET['id'])) { $id = $_GET['id']; $result = odbc_exec($dbConn,"DELETE FROM prodList WHERE prodCode='$id'") or die("ERROR: Cannot Delete Record!"); }这是我的HTML
<html> <head> <title>Delete a Flamingo Product from the list</title> <script src="script/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('a.delete').click(function(e) { e.preventDefault(); var parent = $(this).parent("td").parent("tr"); $.ajax({ type: 'get', url: 'delete.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), beforeSend: function() { parent.animate({'backgroundColor':'#fb6c6c'},300); }, success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); }); </script> </head> <body> <b><font color="#000099"><font size=+2>Flamingo Product List </font></font></b> <img SRC="pinkflamingo.gif" NOSAVE height=85 width=61> <p> <?php /* script to list all the products in the prodList table use default ODBC connection variables $dbConn - database connection $sqlQuery - a query string $dbResult - result of a, SQL query $rows - number of rows */ // connect to the database $dbConn = odbc_connect("flamingo","","") or die("Error opening database .... use the browsers BACK button"); //Veiw record and delete $result = odbc_exec($dbConn,"SELECT * FROM prodList ORDER BY prodCode") or die("Error Retrieving Product Listing"); echo "<table border='1' cellpadding='10'>"; echo "<tr> <th><font color='Red'>Code</font></th> <th><font color='Red'>Name</font></th> <th><font color='Red'>Description</font></th> <th><font color='Red'>Price</font></th> <th><font color='Red'>Delete</font></th> </tr>"; while($row = odbc_fetch_row( $result )) { echo '<tr class="record" id="record-',$row['item_id'],'">'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodCode") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodName") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodDesc") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodPrice") . '</font></b></td>'; echo '<td><b><font color="#663300"><a href="?delete=',$row['item_id'],'" class="delete">Delete</a></font></b></td>'; echo "</tr>"; } echo "</table>"; ?>你能看出我哪里出错了,看看我能做些什么来解决这个问题。
谢谢
I'm trying to get an animated row deletion from a table created in php.
I'm a noob to AJAX and JQuery and i cant seem to see where I have gone wrong. I have also tried to follow the site where I got the code http://davidwalsh.name/animated-ajax-jquery but what seems to happen is that when i click on the delete link nothing happens.
This is my delete.php
// connect to the database $dbConn = odbc_connect("flamingo","","") or die("Error opening database .... use the browsers BACK button"); if (isset($_GET['id'])) { $id = $_GET['id']; $result = odbc_exec($dbConn,"DELETE FROM prodList WHERE prodCode='$id'") or die("ERROR: Cannot Delete Record!"); }This is my HTML
<html> <head> <title>Delete a Flamingo Product from the list</title> <script src="script/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('a.delete').click(function(e) { e.preventDefault(); var parent = $(this).parent("td").parent("tr"); $.ajax({ type: 'get', url: 'delete.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), beforeSend: function() { parent.animate({'backgroundColor':'#fb6c6c'},300); }, success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); }); </script> </head> <body> <b><font color="#000099"><font size=+2>Flamingo Product List </font></font></b> <img SRC="pinkflamingo.gif" NOSAVE height=85 width=61> <p> <?php /* script to list all the products in the prodList table use default ODBC connection variables $dbConn - database connection $sqlQuery - a query string $dbResult - result of a, SQL query $rows - number of rows */ // connect to the database $dbConn = odbc_connect("flamingo","","") or die("Error opening database .... use the browsers BACK button"); //Veiw record and delete $result = odbc_exec($dbConn,"SELECT * FROM prodList ORDER BY prodCode") or die("Error Retrieving Product Listing"); echo "<table border='1' cellpadding='10'>"; echo "<tr> <th><font color='Red'>Code</font></th> <th><font color='Red'>Name</font></th> <th><font color='Red'>Description</font></th> <th><font color='Red'>Price</font></th> <th><font color='Red'>Delete</font></th> </tr>"; while($row = odbc_fetch_row( $result )) { echo '<tr class="record" id="record-',$row['item_id'],'">'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodCode") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodName") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodDesc") . '</font></b></td>'; echo '<td><b><font color="#663300">' . odbc_result ($result, "prodPrice") . '</font></b></td>'; echo '<td><b><font color="#663300"><a href="?delete=',$row['item_id'],'" class="delete">Delete</a></font></b></td>'; echo "</tr>"; } echo "</table>"; ?>Can you see where I have gone wrong, and see what i can do to fix this.
Thanks
最满意答案
我相信你的问题在于这条线:
var parent = $(this).parent("td").parent("tr");$(this)可能返回JQuery $('a.delete').click(function(e) {} 。 尝试在HTML标记中使用ID,以便您可以选择以下元素:
$('#element_id')这可以让您更好地控制您选择的内容。
I believe your problem lies on this line:
var parent = $(this).parent("td").parent("tr");The $(this) is probably returning the JQuery $('a.delete').click(function(e) {}. Try using ids in your HTML tags so you can select the elements like this:
$('#element_id')This can give you more control over what you select.
更多推荐
发布评论