Jump to content

Prestashop 1.6 controller ajax call


Recommended Posts

You have to create a FrontController, defaut.php

class ModuleNameDefaultModuleFrontController extends ModuleFrontController
    public function initContent(){
        $row = array();
            $id_product = (int)Tools::getValue("id_product");
                $row['id_product'] = $id_product;
                $product_informations = Product::getProductProperties($this->context->language->id, $row);
           if (isset($product_informations) and $product_informations)
               $json = array(
                   'productInformations' => $product_informations
                $json = array(
                    'status' => 'error',
                    'message' => $this->l('Error when getting product informations.')

         } else

             $json = array(
                 'status' => 'error',
                 'message' => $this->l('Error when getting product informations.')



JS in the TPL

var id_product = $('input[name="id_product"]').val();
    type: "POST",
    url: '{$link->$this->context->getModuleLink('modulename', 'default')}',
    async: false,
    cache: false,
    data: "product_id="+id_product+"&ajax=1",
    success: function(html){
    error: function() {

You can see using ajax in admin also in this article http://magento-web.blogspot.com/2017/01/utilisation-dajax-en-front-et-back.html

it's in frensh, but i think that the code is clear.

Best regards.

Edited by tarek.fellah (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...