Hi,
We have a part list in the "garagecar/view/index.ctp" view page. The part list is populated with PHP when the page is first loaded. Each part has a remove button. When the user clicks "remove", the controller link removes the part while the JQuery/Ajax removes the HTML that displays the part in the index:
$html->link(__('remove', true),
array('controller'=>'garage_parts',
'action'=>'delete',
$gpart['GaragePart']['id']),
array('class'=>'js-ajax remove_part'));
$(".remove_part").click(function(){
var answer = confirm("Remove this part?");
if (answer){
var partdiv = $(this).parent().parent();
$.ajax({
type: "post",
url: this.href,
});
$(partdiv).remove();
}
return false;
});
When the user wants to dynamically add a new part we use the JQuery $().load function to load "garagepart/view/addpart.ctp". In addpart.ctp, there is a $().ajax function that adds the part via JSON and appends the new part's HTML to the part list in index.ctp.
However, if you click the remove button on this new part, the above JQuery function does not evaluate. The function fails to remove the HTML, even though it is structured exactly the same as the parts preloaded with PHP. The Cakephp remove link still works, so the part is gone if you reload the page.
Why is the JQuery not dynamically removing the part that is dynamically added? The remove only works on parts that were preloaded with PHP and not the new ones that are added via JQuery/Ajax. Please let me know if you need me to post more code... thanks!