繁体   English   中英

在 jQuery Ajax 中传递多个参数?

[英]Pass Multiple parameters in jQuery Ajax?

我有一个表单将 POST 数据发送到一个动作,所以我创建一个带有多个参数的动作是一个FormCollection和一个字符串。 但我不知道如何将它传递给 AJAX jQuery。

这是我的操作方法:

public ActionResult Edit(FormCollection form, string CodeName)
{
        List<Product> PList = (List<Product>)TempData["PListIndex"];
        var index = PList.FindIndex(c => c.Code == CodeName);
        PList[index].NameProduct = form[0];
        PList[index].Price = form[1];
        PList[index].Madein = form[2];

        if (FileFactory.Save(PList, @"DATA\CSDL.DAT"))
            return Json("Success", JsonRequestBehavior.AllowGet);

        return Json("Failed to Save", JsonRequestBehavior.AllowGet);
}

这是我的 Ajax jQuery:

function sendformdata() {
     var form = $("#Edit").serialize();
        $.ajax({
            type: "POST",
            url: '@Url.Action("Edit", "FileEx")',
            data: { form: form, CodeName: _codename } // I don't know how to pass these two parameters
            success: function (response) {
            alert(response);
        }
    });
}

使用serializeArray()而不是serialize() ,然后您可以向数组添加其他元素。

 function sendformdata() { var form = $("#Edit").serializeArray(); form.push({ name: "CodeName", value: _codename}); $.ajax({ type: "POST", url: '@Url.Action("Edit", "FileEx")', data: form, success: function(response) { alert(response); } }); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM