Is there a more effective method to execute a Servlet in the background of a website on Tomcat, rather than the current approach of opening and closing a new window?

Instead of opening and closing a new window to execute a Servlet in the background of a website on Tomcat, a more effective method would be to use AJAX to send a request to the Servlet and handle the response asynchronously. This way, the user experience is improved as the page does not need to reload or open new windows.

<script>
  // Send an AJAX request to the Servlet
  $.ajax({
    url: 'servlet-url',
    type: 'POST',
    data: {param1: 'value1', param2: 'value2'},
    success: function(response) {
      // Handle the response from the Servlet
      console.log(response);
    },
    error: function(xhr, status, error) {
      // Handle any errors
      console.error(error);
    }
  });
</script>