我想在使用$('#myForm').serialize()+额外数据后添加额外的数据
$.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);
}
});
Run Code Online (Sandbox Code Playgroud)
jth*_*son 148
什么样的数据?
data: $('#myForm').serialize() + "&moredata=" + morevalue
Run Code Online (Sandbox Code Playgroud)
"data"参数只是一个URL编码的字符串.你可以随意添加它.请在此处查看API .
就个人而言,我会将元素附加到表单而不是黑客序列化数据,例如
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()
Run Code Online (Sandbox Code Playgroud)
这样,你不必担心?或&