Redirecting the user to the admin table area after publishing a post, getting an invalid response error?

Here’s my working approach with jQuery. Using setTimeout twice because of timing issue. The first setTimeout is used to load the code after everything is loaded on the page.

The second setTimeout is needed to delay page redirection, so Ajax can actually update/publish the post and for better user experience.

    // Redirect to All posts dashboard after post update/publish
function webroomtech_redirect_to_post_list() {
?>
<script>
// On "publish / update / submit changes" button click, redirect to cpt listing
jQuery(document).ready(function($) {

    // Getting the post type to work for post, pages, custom post types etc.
    let postType = document.querySelector('form.metabox-base-form input#post_type').value;

    var url="/wp-admin/edit.php?post_type=" + postType;

    setTimeout(function() {
        $('.editor-post-publish-button__button').on('click', function() {
            setTimeout(function() {
                $.ajax({
                    success: function() {
                        window.location.href = url;
                    }
                });
            }, 2000);

        });
    }, 5000);
  
});
</script>
<?php
}
add_action( 'admin_print_footer_scripts', 'webroomtech_redirect_to_post_list' );

I’ve published the answer originally here: https://www.webroomtech.com/redirect-to-all-posts-after-post-update-or-publish-in-block-editor/