Ajax获取返回ERR_SPDY_PROTOCOL_ERROR

Ely*_*ykx 5 ajax jquery asp.net-core

我正在使用AspNetCore中的webapp,我正试图通过ajax调用从我的控制器获取数据.

这是我的Api:

[HttpGet]
    public async Task<IActionResult> GetPackWithAllCards(int? packId)
    {
        if (packId == null)
        {
            return Json("An error has occured");
        }
        else
        {
            var pack = await _context.Packs
            .Include(p => p.TagPacks)
            .ThenInclude(tp => tp.Tag)
            .Include(p => p.CardPacks)
            .ThenInclude(cp => cp.Card)
            .ThenInclude(c => c.FaceCards)
            .ThenInclude(fc => fc.Face)
            .ThenInclude(fc => fc.Template)
            .Include(p => p.CardPacks)
            .ThenInclude(cp => cp.Card.FaceCards)
            .ThenInclude(fc => fc.Face.Image)
            .Include(p => p.CardPacks)
            .ThenInclude(cp => cp.Card.FaceCards)
            .ThenInclude(fc => fc.Face.Sound)
            .SingleOrDefaultAsync(m => m.PackId == packId);
            if (pack == null)
            {
                return Json("An error has occured");
            }
            return Ok(pack);
        }
    }
Run Code Online (Sandbox Code Playgroud)

和我的ajax电话:

$.get("/pack/GetPackWithAllCards", { packId: pack.packId }, function (pack) {
        alert(pack);
});
Run Code Online (Sandbox Code Playgroud)

我的错误总是一样,我得到"无法加载资源:net :: ERR_SPDY_PROTOCOL_ERROR"状态= 0

我的api正确返回一个包但我的ajax调用没有得到它.

小智 6

这是JSON序列化中的错误.请参阅此处的文档https://docs.microsoft.com/en-us/ef/core/querying/related-data#related-data-and-serialization

基于github:https://github.com/aspnet/EntityFrameworkCore/issues/9573.我发现它只能部分解决我的问题.在模型中删除不必要的引用修复了该问题.

  • 链接重的答案不适用于这个网站,因为他们保证腐烂.因此随着时间的推移,它将变得不那么有用 你能引用相关部分来更清楚地解释你的答案吗? (3认同)