开发者

serialize variable merge?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜