I have some buttons that I call ajax with.
Basically I do this
$.ajax(
{ url: url,
data: data,
dataType: "json",
type: "POST"
}).always(function(d){CheckHoursStatus(d, action);});
Then in CheckHoursStatus, I either add rows to a table or remove rows from a table based on the action something like this
//this function takes in a status
//if it's an error, it shows the div, otherwise it adds the data
function CheckHoursStatus(d, action){
if(action == "AddHours"){
$("#hoursTable > tbody").append("<tr id='hoursRow" + d.id + "'><td>"+ $("#dayOperation").val() + "</td><td>" + startDate.toLocaleTimeString() +
"</td><td>" + endDate.toLocaleTimeString() + "</td>" + btn + "</tr>");
}
$("#addHoursOutput").fadeIn("medium");
setTimeout("HideDiv('addHoursOutput')", 5000);
}//if action == AddHours
else if(action == "DeleteOperationHours"){
$("#hourRow" + d.rowid).remove();
}//else if
They both work if you only do one. I.e if you just add all the time, the rows get added. If you remove, the rows get removed. However, as soon as you add a row then remove, nothing happens and vice versa. Any ideas why?