Deleted categories still listed until additional page refresh

I’ve found a workaround by forcing the second refresh, but I’m sure there’s probably a better way to do this.

In order to make the process smoother for the user, I’m thinking I’ll have to do an AJAX post and then refresh on success to show the updated data.


if ( isset($_POST['deleteSelectedCategories']) ){

    $cats = $_POST['catsToDelete'];
    $catsArray = explode(',', $cats);

    $success = 0;

    foreach ($catsArray as $catID) {
        if ( wp_delete_term( $catID, 'category' ) ) {
            $success++;
        }
    }

    if ($success > 0) {
        echo '[Here I have some HTML to block out the screen 
            and show a message to the user, 
            and then the following meta refresh:] 
            <meta http-equiv="refresh" content="0" />';
    }
}