在jQgrid中使用"formDeleting"时如何添加额外的参数发送到服务器?



当我尝试删除jQgrid中的一行或多行时,我需要发送一个额外的参数。我发现了以下内容:

  • 删除行时 jq网格附加开机自检数据
  • jqGrid (删除行( - 如何发送额外的 POST 数据?

但这些都是一两年前的答案,我认为jQgrid从那时起就发生了变化。我正在使用jQgrid的formDeleting选项,定义如下:

formDeleting: {
    url: '/ajax/forms/delete',
    delicon: [true, "left", "fa-scissors"],
    cancelicon: [true, "left", "fa-times"],
    width: 320,
    caption: 'Delete form',
    msg: 'Are you sure you want to delete this form?',
    beforeShowForm: function ($form) {
        var rowids = $form.find("#DelData>td").data("rowids");
        if (rowids.length > 1) {
            $form.find("td.delmsg").html('Are you sure you want to delete all the selected forms?');
        }
    },
    afterComplete: function (response, postdata, formid) {
        if (response.responseText === "true") {
            alert("The form was deleted successfully.", "Information");
        } else {
            alert("Something went wrong, the form could not be deleted.", "Error");
        }
    }
}

如何向请求添加额外的参数,以便我可以在后端获取它?

我建议您在答案附近使用onclickSubmit回调,但将onclickSubmit回调的代码放在formDeleting内。在formDeleting内部使用序列化DelData也是可能的formDeleting但是最好在发布的数据发生更深层次更改的情况下使用它,例如JSON.stringify的使用。

最新更新