Ajax: Delete Records using a LINK
Hello,
I'm currently working on a ajax-based website with jquery.
Index.php contains a div container, which the new data from
read.php is loaded in, by jquery after a set interval of seconds. That all works like a charm.
Now comes to problem, the
read.php lists several records, which are read from a database.
I was looking for a possibility deleting those records using jquery ajax. Which means there's a delte LINK next to each record.
I've been search through the web for almost two days and found one example which unforunatley doesnt work for me. Maybe you guys might help me.
This is a part from my
read.php, which displays the delete link.
$idd = the message-id from the database.
$record = record from database
-
.....
<div id="record">$record</div><div class="box" id="delete-'.$idd.'"><a href="#">delete</a></div>
.....
This is the custom.js which is included in the index.php via <script>...
-
.....
$(function(){
$('.box a').click(function() {
id = $(this).parents('div.box').attr('id');
el = $(this);
$.post('index.php', { deleteid: id, ajax: 'true' }, function() {
$(el).parents('div.box')
.animate( { backgroundColor: '#cb5555' }, 500)
.animate( { height: 0, paddingTop: 0, paddingBottom: 0 }, 500, function() {
$(this).css( { 'display' : 'none' } );
});
});
});
});
And last but not least a snippet from my
index.php, which deletes the entries from database where 'deleteid = id'.
-
if(isset($_POST['deleteid']))
{
$query1 = 'DELETE FROM database WHERE id = '.(int)$_POST['deleteid'];
$result = mysql_query($query1);
}
I'm currently using firebug addon to eliminate bugs and errors but I noticed when clicking the links, the index.php is not even called.
Another thing I noticed is that, when I had those delte-links created in the
index.php instead of the
read.php file,
everything worked fine.
Just can't handle things in the index.php, i gotta handle them in the read.php
I really appreciate your help
Greetings from germany