Jump to content

Pass data from js to controller


Recommended Posts

Hi guys,😀
My name is Enrico and I'm newbie in Prestashop (and surely the problem will be stupid) but I'll talk about what I'm doing and the problem I have.
Yesterday I created my first module. 
This module will serve to customize product after some selections and fields to fill out.
To make selection end fill field I have a structure in tabs...
First Tab            -> first selection from three
Second Tab      -> second selection from other three
ecc ecc.....
and so far so good

In separate js I've the function that every click to change tabs the variables records the user's chooses and I generate an array with all chooses.

I should pass the array via ajax from this js file  stored in (root->modules->configuratore->views->js->configuratore.js) to my php file that stored in (root->modules->configuratore->controller->front->configuratore.php)
but...I don't understund why ajax url give me 404

var ciao = 'ciao';
$.ajax({
	url: ????, // I've try different urls but every url with 404 in console
	type: 'GET',
	dataType: 'json',
	data: {ciao: ciao},
	})

I accept any advice thanks😉

Link to comment
Share on other sites

try this:

$.ajax({
        type: 'POST',
        dataType: 'json',
        url: 'ajax-tab.php',
        data: {
          //required parameters
          ajax: true,
          controller: 'AdminYourController',
          action: 'YourAction',
          token: $('#update').attr('data-token'), //set the token in template
        },
      })
      .done(function() {
        console.log('Succes!');
      })
      .fail(function() {
        console.log('Fail!');
      });

 

Link to comment
Share on other sites

On 3/30/2019 at 10:12 AM, Rhobur said:

try this:


$.ajax({
        type: 'POST',
        dataType: 'json',
        url: 'ajax-tab.php',
        data: {
          //required parameters
          ajax: true,
          controller: 'AdminYourController',
          action: 'YourAction',
          token: $('#update').attr('data-token'), //set the token in template
        },
      })
      .done(function() {
        console.log('Succes!');
      })
      .fail(function() {
        console.log('Fail!');
      });

 

Thank for your help.
I founded an help in other thread by Razaro
but I can't get the value with Tool::getValue ()
the result is empty

Link to comment
Share on other sites

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...