Jump to content

Ajax variables are not transmitted eventhough code 200 is displayed


Kathleen86

Recommended Posts

Hello everybody,

I would like to pass on the variables displayed in data to a file.

The success code displayed is 200 but no variables are transmitted (this is what I noticed via the console).

I would need your help to check why the variables checkStatut, id_product and id_product_attribute are not tranmitted via ajax.

 

Thank you very much !

 

window.onload = function() 

{

    $(document).on('click', '.check', function(e){

        e.preventDefault();

        var id_product_attribute = parseInt($(this).val());

        var id_product = parseInt($(this).next().val())

        console.log(id_product);

        var ajaxaecattribute=url not displayed

        $.ajax({

            type: 'POST',

            url: baseDir+ajaxaecattribute,

            data: 

                'checkStatut'+1&

                'id_product'+ id_product&

                'id_product_attribute'+ id_product_attribute,

            

            dataType: 'json',

            success: function(html) {

                showSuccessMessage(html.text);

                var result = parseInt(html.result);

                if (result === 1) {

                    $(this).attr('checked', true);

                } else {

                    $(this).attr('checked', false);

                }

            },

            error : function(data){

                showErrorMessage('erreur');

            }

        });

    });

}

Link to comment
Share on other sites

your syntax of data is a little bit strange; if you want to sent data in "query parameter" form, you can do it like as

 


        $.ajax({

            type: 'POST',

            url: baseDir+ajaxaecattribute,

            data: 

                'checkStatut=1&id_product='+ id_product +'&id_product_attribute='+ id_product_attribute,

            dataType: 'json', 

but you will have to parse this string in php

I would suggest to set data this way:

    var adata = {
	'checkStatut':1,
	'id_product':id_product,
	'id_product_attribute':id_product_attribute
    };
	$.ajax({

            type: 'POST',

            url: baseDir+ajaxaecattribute,

            data: JSON.stringify(adata),

            dataType: 'json', 

then you can get all variables using Tools::getValue
f.e. Tools::getValue('id_product')

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