When we have to use Ajax in Prestashop front development, we have to create a file where we can perform the process. Generally, we have created an ajax folder and in that folder, we create and file ajax.php for our ajax processing, in this file we have to load Prestashop Classes by including config.inc file.
But instead of this, we can create a PrestaShop front controller and use this front controller for ajax processing.
Simply create a Front controller if not exist OR use the existing controller and process your Ajax on the same.
Prestashop front controller always has the HTML of Header and Footer, So while ajax response, we have to hide them.
If we are using the existing Front Controller where the other operation also performs, We have to create a condition in which we can hide the header and footer
Define display_header and display_footer variable false in Front Controller file init function
public function init() { if (Tools::getValue('ajax')) { $this->display_header = false; $this->display_footer = false; } }
Otherwise, simply define init function like this,
public function init() { $this->display_header = false; $this->display_footer = false; }
Be the first to comment.