Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass a variable to php page beside this.serialize with AJAX

I need to pass a variable from ajax to php beside the serialize data.

My code will explain what I mean:

        $('#update_form').on('submit', function(e){
            e.preventDefault();
            var total = parseFloat($('#total').text()); // This is the var I want to pass
            if($('.check_box:checked').length > 0)
            {
                $.ajax({
                    url:"pages/Model/multiple_update.php",
                    method:"POST",
                    data:$(this).serialize(),
                    success:function()
                    {
                        alert('Data Updated');
                        $('#multiple_update').attr('disabled', 'disabled');
                        fetch_data();
                    }
                });
            }
        });

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

serialize() creates a querystring in the format a=1&b=2 so you could add to it like this

var total = parseFloat($('#total').text()); 
var qs = $(this).serialize() + '&total=' + total;

and then send that

data:qs,

Or

data:$(this).serialize() + '&total=' + total,
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading