I am trying to delete records from database without reloading the page. In the view file I have the following code. But when I click on the delete link nothing happens. Would you please kindly help me find out where I have done wrong?
Thanks in advance.
My view file:
<script type="text/javascript">
$(function(){ // added
$('a.delete').click(function(){
$.ajax({
var a_href = $('selector').attr('href');
type: "POST",
url: "<?php echo base_url(); ?>student_fee_status/payment_info_delete",
data: "id="+a_href,
success: function(html){
$("#show").html(html);
}
});
return false
});
}); // added
</script>
<?php if(count($records) > 0) { $i = 0; foreach ($records as $row){ $i++; ?>
<span> <?php echo $row['fee_type']; ?> : <?php echo $row['fee_amount']; ?> [<a id='<?php echo "$paymentid" ;?>'
class='delete' href='#'>Delete</a>]</span> <br>
<?php }} ?>
This is my Controller:
function payment_info_delete(){
$id = mysql_real_escape_string($_POST['id']);//Some clean up :)
$query= $this->db->delete('studentpayment2', array('pid' => $id));
echo "$id";
}