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();
精彩评论