文档就绪循环运行(添加查询字符串后)

document ready runs in a loop (after adding query string)

我有一个 returns 视图并将视图模型传递给视图的操作方法, 在我的应用程序的另一部分调用此方法并传递输入参数后 url 看起来像这样 (localhost:51999:\Home\Onlineplayer{guid})

 public async Task<IActionResult> OnlinePlayer(Guid id)
    {
        if (id != Guid.Empty)
        {
            var requestedFeed = await _feedService.FindOneAsync(id);
            var feedOwnerName = requestedFeed.OwnerName;
            
            ISpecification<Feed> spec = new FeedWithNotEndedStateSpec()
                .And(new FeedWithVerifiedStateSpec())
                .And(new FeedWithSpecificOwnerNameSpec(feedOwnerName));

            onlinePlayerVm.LatestMusics = await _feedService.GetListBySpecAsync<FeedPlayerDTOVm>
                    (new PaginationFilter(), spec);

            return View(onlinePlayerVm);
        }
        onlinePlayerVm.LatestMusics = 
            await _feedService.GetListAsync<FeedPlayerDTOVm>(new PaginationFilter(1, 20));
            
        return View(onlinePlayerVm);
    }

OnlinePlayer.cshtml有一个'document.Ready()'jquery函数可以在页面加载时调用一些函数:

<script src="~/js/Custom/AudioPlayer.js" asp-append-version="true"></script>

<script>

    $(document).ready(function () {
        _latestMusicCurrentPage = 1;
        _topMusicCurrentPage = 1;
        _popMusicCurrentPage = 1;

        //GrabLatestMusics();

        if (@User.Identity.IsAuthenticated.ToString().ToLower()) {
            SaveLocalPlaylistToDatabaseAfterLogin();
            //GrabUserPlaylists();
        }
        //LoadLocalPlaylists();

        var item = $("#playlistContainer").find("p[data-id=1]");
        PlayThisFromList(this, item, false);


        $(".RemoveFromList").click(function (e) {
            var dataId = $(this).attr('data-id');
            $(this).closest("p[data-id='" + dataId + "']").remove();
            e.stopPropagation();
        });

        $(".DownloadThisMusic").click(function (e) {
            var dataId = $(this).attr('data-id');
            PNotifyToasterWithParam("error", "پیاده سازی نشده است")
            e.stopPropagation();
        });

    });
    function GrabLatestMusics() {
        debugger
        $.post('LatestMusic', { pageIndex: _topMusicCurrentPage }, function (data) {
            $("#latestSongsContainer").append(data);
        }).done(function () {
            SetColumntResizingAfterPlayerHidden();
        });;
    }
</script>

问题GrabLatestMusics() 函数是注释时,页面及其脚本工作正常,但在取消注释此函数并在 url 查询字符串中传递和 Id 后,页面将崩溃并记录准备一遍又一遍地执行并向控制器中的 OnlinePlayer(Guid id) 操作方法发送无限请求。我该如何解决这个问题!?

在 GrabLatestMusics 方法中,您应该对 Controller 和 Action 使用完整地址。 (如果需要,也可以是区域)

function GrabLatestMusics() {
        $.post('/YourArea/YourController/LatestMusic', ...