Hello All -
I'm still pretty new at javascript but I've got a few functions that are working pretty well with one exception.
Here's the scenario:
1. User deletes an item from a page.
2. javascript function deletes the target item from the database and then reloads the remaining items from the same table.
3. a modal dialog appears notifying the user that the item has been successfully deleted. The user must click the "OK" button on the modal for it to dismiss.
All of the above works fine, except when...
The user deletes the LAST ITEM on a page window.location.href take the user to another page.
Under this circumstance, the:
- Item is deleted
- User is automatically re-directed
- Modal appears, but disappears within a few seconds without the user needing to click the ok button.
What is appearing to happen is that window.location.href is still happening when the modal is fired... but what's weird is that window.location is called BEFORE the model is called.
The actual code-calls are here:
// Redirect if needed
if(data.redirect) window.location.href = data.redirect;
// Display remaining data from database
if(data.content) {
$("#tableData").html(data.content);
$("#dashboardData").html(data.dashboard);
}
// Fire confirmation modal dialog
simpleDialog(part)
Anyone got any idea on how to (if this is even the problem) make sure the re-direct has completed BEFORE the modal is called.
All guidance gratefully appreciated!