从jQuery AJAX获取对象get方法

问题描述

在我的ASP.NET Mvc中,我决定使用Ajax更新我的局部视图。如果get方法成功,则它将传递的对象传递给@Html.Partial方法。但是,在$("#Flashcards").html("@Html.Partial("_Flashcard",c)");行中,它告诉我c does not exist in the current function.

<script>
    $("#startReview").click(function () {
        $.ajax({
            type: "GET",url: "/VolunteerEvent/GetEvents",success: function (c) {
                $("#Flashcards").html("@Html.Partial("_Flashcard",c)");
            },error: function (error) {
                $("#Flashcards").html("<p>You have no cards ready for review</p>")
            }
        })

    });
</script>

我尝试添加一个对象,但是它仍然无法识别引用,并说card does not exist in the current function

<script>
    var card;
    $("#startReview").click(function () {
        $.ajax({
            type: "GET",success: function (c) {
                card = {
                    Id: c.Id,CardFront: c.CardFront,CardBack: c.CardBack,Deck: c.Deck
                };
                $("#Flashcards").html("@Html.Partial("_Flashcard",card)");
            },error: function (error) {
                $("#Flashcards").html("<p>You have no cards ready for review</p>")
            }
        })

    });
</script>

解决方法

您可以在成功获取请求中为部分视图添加发布请求。

TcpStream::connect_timeout()

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...