ajax 成功响应更改为 @html.raw

ajax success response change as @html.raw

我的 Razor 视图页面中有以下 jquery 代码

$(document).ready(function () {

    var grouplistvalues = @Html.Raw(Json.Encode(Session["grouplist"]));


    $("#nsline").click(function () {

        alert(grouplistvalues)

        $.ajax({
            type: "POST",
            url: "SetupGroups",
            data: { grouplist : grouplistvalues },
            dataType: "html",
            success: function (response)
            {
                grouplistvalues = null;
                grouplistvalues = response;
                alert(response)
            },
            error: function ()
            {

            }
        });

    });


    $("#ewline").click(function () {

        $.ajax({
            type: "POST",
            url: "SetupGroups",
            data: { grouplist : grouplistvalues },
            dataType: "html",
            success: function (response)
            {
                grouplistvalues = null;
                grouplistvalues = response;
            },
            error: function ()
            {

            }
        });        

    });

在上面 grouplistvalues 中,它把会话作为 html 原始

当我在 #nsline 点击功能上提醒它时,我可以看到它,

在上面的函数中我调用了 ajax 函数和上面的 grouplistvalues 值更新

一旦我在 #nsline 点击功能成功响应时提醒它,我可以看到如下所示的提醒

因为这个(grouplistvalues 值)1,2,.. 更改为 [1,2..] 由于参数不同,我无法在 #ewline click 函数中调用其他 ajax 函数,

这是上面常见的ajax调用

    [HttpPost]
    public JsonResult SetupGroups(long[] grouplist)
    {
        Session["grouplist"] = null;

        List<long> groupList = new List<long>();

        foreach (var groupitem in grouplist)
        {
            groupList.Add(groupitem);
        }

        long[] grouparray = groupList.ToArray();
        Session["grouplist"] = grouparray;

        return Json(grouparray);
    }
}

虽然我有两个点击功能,但它只在第一次点击时起作用(只有第一次点击 ewline 或 nsline)

如何解决这个问题

这是您 ajax 请求中的 dataType。应该是 json:

dataType: "json"