从数据库中删除AJAX JQuery(AJAX JQuery delete from database)

编程入门 行业动态 更新时间:2024-10-25 05:12:08
数据库中删除AJAX JQuery(AJAX JQuery delete from database)

我试图从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&nbsp;</font></font></b> &nbsp;&nbsp;&nbsp;&nbsp;<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&nbsp;</font></font></b> &nbsp;&nbsp;&nbsp;&nbsp;<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.

更多推荐

本文发布于:2023-08-06 13:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   AJAX   JQuery   delete   database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!