开发者

serialize variable merge?

开发者 https://www.devze.com 2023-04-05 07:27 出处:网络
I want to add data of ExtrasGroupID variable into options serialize variable (or what is other way), how can that be done?

I want to add data of ExtrasGroupID variable into options serialize variable (or what is other way), how can that be done?

Example below:

var ExtrasGroupID = $("#SelectExtrasGroup option:selected").val();
var options = $("#FormExt开发者_Go百科rasOptionsList").serialize();

$.post("ajax.php", options,
  function(data)  {
        console.log(data)
  });


Try this:

var ExtrasGroupID = $("#SelectExtrasGroup option:selected").val();
var options = $("#FormExtrasOptionsList").serialize();

// make sure you set an appropriate key for the new value
options = options + '&' + $.param({ 'select-extras-group': ExtrasGroupID });

...


Edit: More info on $.param: http://api.jquery.com/jQuery.param/


You could also do a one liner:

var ExtrasGroupID = $("#SelectExtrasGroup option:selected").val();
var options = $("#FormExtrasOptionsList").serialize();

$.post("ajax.php", (options = options.split('&')).concat(['extras_group_id='+ExtrasGroupID]).join('&'),
    function(data)  {
        console.log(data)
});


You can use .add:

var options = $("#FormExtrasOptionsList").add(ExtraGroupId).serialize();
0

精彩评论

暂无评论...
验证码 换一张
取 消