Hi all, Another one of those "I wonder how others..." questions I have.
For this case I have one or more <items> that can be placed into a <container>. I have a method called "deleteItem" and I have a method called "deleteContainer" "deleteItem" checks some stuff, prompts maybe a confirm dialog, and does ajax request to actually delete the item from a database or kills a file. This all results in either a succesfull delete or an error. "deleteContainer" should destroy the whole container (e.g. it's a div holding various item-divs) and my idea is to: 1. Check for items inside. 2. If there are any, loop through the number of items and call the "deleteItem" for each item. 3. Kill the container (e.g. in a database and/or on screen destroying the element). Ok, so I would like to cancel the "deleteContainer" action if there's a problem with "deleteItem" for one of the items inside the container. You know; perhaps the ajax request generated an error, or the user pressed cancel on the confirm dialog. The process should stop and the container should not be deleted. Because JS is asynchronous, the code below a foreach loop (the foreach to delete all items in container) that will destroy the container is executed instantly and doesn't wait for the dialog or an ajax error inside the deleteItems method. Does this make sense? I'm now handling this server side: detroying container runs php and first deletes any elements from the database and if there's no error, it will destroy the container. This will either return a complete success or an error with details so that in the JS I can see what happened and what I should do visually on screen. But are there any tips, examples, best practices, ideas on how to handle this within a JS class? Cheers, Rolf
