To pass Ajax response from the controller in Magento 2, You need to use Magento\Framework\Controller\Result\JsonFactory Object.
Many times your custom functionality requires you to use Ajax request on a page to display information without any page load and in this situation, you need to know about Ajax use in Magento 2 to achieve your requirement.
Magento\Framework\Controller\Result\JsonFactory is used for sending a response from a controller to an Ajax request.
Pass your response in the setData() method. Continue reading “How to get Ajax Response from controller file Magento 2?”