How to ajax request to custom page in prestashop 1.7

Prabhakaran A picture Prabhakaran A · Jun 2, 2017 · Viewed 8.7k times · Source

Am apology for my bad english. Am new to prestashop. Please anybody help. How to send AJAX request to custom php file in prestashop

//My js file
     $.ajax({
     url : baseUrl + "modules/<myModule>/ajaxfunc.php",
     type: "POST",
     cache: false,
     data : {form_data: 1 , action:'imageuploadAction'},

     beforeSend: function() {
     $('body').append('<div class="loading_popup">Loading...</div>');},        

    success: function(data){
    console.log(data);
       }
      });

// php file
// modules/<myModule>/ajaxfanc.php

   <?php
   include_once('../../config/config.inc.php');
   include_once('../../init.php');
   class ajaxfuncAjaxModuleFrontController extends ModuleFrontController
    {
    public function  imageuploadAction() {
     die('here');
    }
   }
   ?>

I didn't know its be correct or not. please guide me.

Answer

Dennis de Best picture Dennis de Best · Jun 5, 2017

You can use an ajax front controller in your module and generate the URL you need for the Ajax request in the module itself with a hook.

See Make an ajax request from a Prestashop module