I am trying to use jquery and ajax to remove the a row on the page and a record in the db but it's not working for me. The row on the page is removed successfully but the php file is not getting called. I just have an echo statement in the php to error check and that is not getting printed to the screen.
js file
function deleteLine(a,estimateNum,rowNum){
var $rowcount = $("#desc_table tr").length;
if($rowcount <= 2){
alert("Cannot remove all the description lines.");
return false;
}
else{
if (confirm("Are you sure you want to delete?")) {
$.ajax({
type: "POST",
url: "delete_desc_record.php",
data: { estimate_num: estimateNum, row_num: rowNum },
cache: false,
success: function(){
a.closest('tr').remove();
}
});
}
else{
return false;
}
}
delete_desc_record.php
<?php
include 'connect.php';
include 'set_variables.php';
$estimate_num = isset($_POST['estimate_num']) ? (int) $_post['estimate_num'] : 0;
$row_num = isset($_POST['row_num']) ? (int) $_post['row_num'] : 0;
echo 'in delete php file '. $estimate_num .' '. $row_num;
index.php
if(!empty($DESC)){
foreach ($DESC as $i => $b) {
?>
<tr>
<td><input name="desc[]" type="text" value="<?php echo $DESC[$i]; ?>"></td>
<td> <input name="desc_hr[]" type="text" value="<?php echo $DESC_hr[$i]; ?>"</td>
<td> <input name="desc_rt[]" type="text" value="<?php echo $DESC_rt[$i]; ?>" </td>
<td><input name="desc_amt[]" type="text" value="<?php echo $DESC_amt[$i]; ?>"></td>
<td><input type="button" value="X" name="delete" class="btnDelete" onclick="deleteLine(this,<?php echo $estimate_num .','. $i; ?>)"></td>
</tr>
<?php
}
}