简体   繁体   English

ajax成功后对局部视图进行Ajax调用

[英]Making an Ajax call to a partial view after ajax success

I have a partial view that contains all my buttons and it needs to display updated values after a form is submitted. 我有一个包含所有按钮的局部视图,并且在提交表单后需要显示更新的值。 At the submission I already have it rendering another partial view, is there a way to make it work where on success of that one being rendered it re-renders. 在提交时,我已经渲染了另一部分视图,有没有一种方法可以使它在渲染成功的地方重新渲染。 Here is the code I am trying to get to work now based on what I've seen in other places. 这是我在其他地方看到的代码,现在我要开始工作的代码。

jQuery in my view: jQuery在我看来:

<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
    $('#ChangeGrade').click(function (e) {
        var tdata = $('#form1').serialize();
        var origname = $('#HeatGradeDiv').find('input[name="grade"]').first().val();
        var newname = $('#HeatGradeDiv').find('input[name="updatedGrade"]').first().val();
        var heatname = $('#HeatGradeDiv').find('input[name="hiddenHeat"]').first().val();
        $.ajax({
            type: "POST",
            data: {
                mCollection: tdata,
                grade: origname,
                updatedGrade: newname,
                hiddenHeat: heatname

            },
            url: '@Url.Action("ChangeGrade","Home")',
            success: function (result) { success(result); }
        });
    });


    function success(result) {

        $('#HeatGradeDiv').dialog('close');
        $("#Partial_Chem_Analysis").html(result);
        //ajax call I'm trying to get working
        $.ajax({
            type: "POST",
            url: "/Home/ButtonsPartial",
            success: function (result2) { $("#ButtonsPartial").html(result2); }
        });
    }
});
</script>

Here is the controller method I'm calling. 这是我正在调用的控制器方法。 When I run it now it is not getting hit. 现在运行时,它没有受到打击。

public ActionResult ButtonsPartial()
    {
        ButtonsModel B = new ButtonsModel();
        B.GetData(searchQ);

        return PartialView(B);
    }

Any help is appreciated. 任何帮助表示赞赏。

If you attach it to a debugger such as (chrome developer tools or firebug) are you seeing any http or js errors? 如果将其附加到调试器(例如chrome开发人员工具或firebug),是否会看到任何http或js错误?

It looks like you might need to make it a GET rather than POST... 看来您可能需要使其成为GET而不是POST ...

$.ajax({
            type: "GET",
            url: "/Home/ButtonsPartial",
            success: function (result2) { $("#ButtonsPartial").html(result2); }
        });

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

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