I have an AJAX call using jQuery:
$('.add a').click(function() {
$.ajax({
type: 'POST',
url: '/ajax/fos',
context: this,
datatype: 'html',
success: function(data){
$(this).parents('tr').before(data);
}
});
});
Once it runs, it adds a new row to a table. The row is verbatim to other rows in the table (structure-wise), but with no data.
I have two other jQuery calls that manipulates the data on the row, but the calls don't work on the new table rows using the AJAX call. Specifically, when a drop-down (select/option) list changes, it does an AJAX call to replace the contents of another drop-down list. Another function removes the row if you want to delete it.
These are the functions that are not working:
$('.fos').change(function() {
$.ajax({
type: 'POST',
url: '/ajax/courses',
context: this,
data:({
fos_id: $(this).val(),
name: $(this).find(':selected').text()
}),
success: function(data){
$(this).next().html(data);
}
});
});
$('td.remove a').click(function() {
$(this).parents('tr').remove();
});
Does this have something to do with the AJAX call not registering the new row with DOM or can this not be done?