我正在尝试在使用beforeSend函数发布之前向表单添加一些数据,但数据未在帖子中传出。我猜这个表单在添加数据之前被序列化了,但这只是一个猜测。
这是我的jquery / ajax:
$.ajax({
type: "POST",
url: '@Url.Action( "SaveHeaders", "Tally" )',
//data: { model: @Html.Raw(Json.Encode(@Model)) },
data: $('#myForm').serialize(),
beforeSend: function() {
var displayIndex = imageIndex+1;
$("#images tbody").append("<tr><td class='text-center align-middle'>" + displayIndex + "<input type='hidden' id='SellerGroup_" + imageIndex + "__imageId' class='form-control text-box single-line' name='SellerGroup[" + imageIndex + "].imageId' readonly='readonly' value='" + $('#imageName').val() + "' /><td><input type='text' id='SellerGroup_" + imageIndex + "__majorGroup' class='form-control text-box single-line' name='SellerGroup[" + imageIndex + "].majorGroup' readonly='readonly' value='" + major + "' /></td><td><input type='text' id='SellerGroup_" + imageIndex + "__minorGroup' class='form-control text-box single-line' name='SellerGroup[" + imageIndex + "].minorGroup' readonly='readonly' value='" + minor + "' /></td></tr>");
},
success: function (data) {
console.log(data);
}
});
答案 0 :(得分:1)
之前您运行$.ajax(...)
代码,请尝试将其设为:
$('#myForm').append('<input type="hidden" name="whateverName" value="whateverValue" />');
然后才运行您的代码(使用$('#myForm').serialize()
方法)。