gpt4 book ai didi

jquery - AJAX Post int 数组和序列化表单数据

转载 作者:行者123 更新时间:2023-12-01 04:51:03 25 4
gpt4 key购买 nike

我正在尝试将表单数据与整数数组一起发布。我无法找到我在这段代码中出错的地方。请帮助我找到错误

    var DetailID = new Array();

$.each(selected, function (i, n)
{
var detailID = $(this).attr('data-record-key');
DetailID.push(detailID);

});
var data = $('#form').serialize();
var finaldata = data + '&' + DetailID;

if ($('#form').valid())
{
$.ajax({
url: $('#form').attr('action'),
type: $('#form').attr('method'),
traditional: true,
dataType: "json",
data:finaldata,
contentType: 'application/json; charset=utf-8',
success: onSuccess,
error: onFailure
});
}

我的 Controller :

public ActionResult Merge(Merge merge)
{

}

我的模型:

public class Merge
{
public string ItemCode { get; set; }

public string ItemDescription { get; set; }

public int[] DetailID { get; set; }
}

最佳答案

尝试

var finaldata = data + '&' + $.param({DetailID: DetailID});

if ($('#form').valid())
{
$.ajax({
url: $('#form').attr('action'),
type: $('#form').attr('method'),
//traditional: true, -- finaldata is a string so this doesn't matter
dataType: "json", // are you returning a json response?
data: finaldata,
//contentType: 'application/json; charset=utf-8', -- you aren't sending json
success: onSuccess,
error: onFailure
});
}

关于jquery - AJAX Post int 数组和序列化表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19998892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com