i am unable to delete records from database, fetching code is working but delete code is not working. please help me out.. thanks in advance
code to fetch data with ajax
$(document).ready(function(){
done();
});
function done(){
setTimeout(function(){
updates();
done();
}, 200);
}
function updates(){
$.getJSON("fetch.php",function(data){
$("table").empty();
$("table").append("<tr><td>Name</td><td>Date</td><td>Delete</td></tr>");
$.each(data.result, function(){
$("table").append("<tr><td>"+this['text']+"</td><td>"+this['date']+"</td><td><a id='del' href='"+this['id']+"'>Del</a></td></tr>");
});
});
}
code to delete data with ajax
$(function() {
$("#del").click(function(){
var element = $(this);
var id = element.attr("id");
var dataString = 'id=' + id;
if(confirm("Sure you want to delete this comment?"))
{
$.ajax({
type: "GET",
url: "del.php",
data: dataString,
success: function(){
}
});
}
return false;
});
});
php code del.php
$last_page_id = $_REQUEST['d_i_d'];
$sql = mysql_query("delete from time where id = '{$last_page_id}'");
if(!$sql){
echo mysql_error();
}else{
header('location: index.php');
}