AJAX is used to communicate with the server to perform the action without the need to refresh the page.
You can either handle AJAX requests on the same page or on a separate page.
In this tutorial, I show how you can send and receive AJAX requests on the same page.