附加到formData不起作用

时间:2017-10-09 17:58:27

标签: javascript jquery ajax append

我在将数组附加到formData后发送formData保存数组。但是当我在控制器中调试时,除了列表之外我还得到了整个数据。所以我想知道我是否犯了代码错误。因为在源代码调试中,我没有添加数组的任何错误。确切的问题是附加,因为我试图附加一个文本区域,但仍然附加工作

下面是javascript代码

function SubmitForm(form) {
    RoleCapabilities = new Array();

    $('#destinationItems option').each(function () {
        var RoleCapability = {
            "Id": "", "RoleId": "", "CapabilityId": "",
            "AccessFlagId": "", "InsertedDate": "", "InsertUserId": "",
            "UpdateUserId": "", "UpdatedDate": ""
        };
        RoleCapability.Id = 0;
        RoleCapability.CapabilityId = this.value;
        RoleCapability.RoleId = 1;
        RoleCapability.AccessFlagId = 1;
        RoleCapability.InsertedDate = getDate(new Date());
        RoleCapability.InsertUserId = 1;
        RoleCapability.UpdatedDate = getDate(new Date());
        RoleCapability.UpdateUserId = 1;

        RoleCapabilities.push(RoleCapability);
    })

    debugger;

    $.validator.unobtrusive.parse(form);
    var formData = new FormData($(form)[0]);
    var json_arr = JSON.stringify(RoleCapabilities);


    formData.append('RoleCapabilities', json_arr);
    formData.append('RoleName', 'test');


    if ($(form).valid()) {
        $.ajax({
            type: form.method,
            url: form.action,
            //"datatype": "json"
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.success) {
                    Popup.dialog('close');
                    dataTable.ajax.reload();

                    $.notify(data.message, {
                        globalPosition: "top center",
                        className: "success"
                    })

                } else {
                    Popup.dialog('close');

                    $.notify(data.message, {
                        globalPosition: "top center",
                        className: "error"
                    })
                }
            }
        });
    }
    return false;
}

0 个答案:

没有答案