简体   繁体   English

如何将变量传递到此旁边的 php 页面。使用 AJAX 进行序列化

[英]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.我需要将一个变量从 ajax 传递到序列化数据旁边的 php 。

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();
                    }
                });
            }
        });

serialize() creates a querystring in the format a=1&b=2 so you could add to it like this serialize() 以a=1&b=2格式创建一个查询字符串,因此您可以像这样添加它

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

and then send that然后发送

data:qs,

Or或者

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM