I want to add extra data after i use $('#myForm').serialize() + extra data
$.ajax({
type: 'POST',
url: $('#myForm').attr('action'),
data: $('#myForm').serialize(), // I WANT TO ADD EXTRA DATA + SERIALIZE DATA
success: function(data){
alert(data);
$('.tampil_vr').text(data);
}
});
This question is related to
jquery
You can do it like this:
postData[postData.length] = { name: "variable_name", value: variable_value };
Personally, I'd append the element to the form instead of hacking the serialized data, e.g.
moredata = 'your custom data here';
// do what you like with the input
$input = $('<input type="text" name="moredata"/>').val(morevalue);
// append to the form
$('#myForm').append($input);
// then..
data: $('#myForm').serialize()
That way, you don't have to worry about ?
or &
Source: Stackoverflow.com