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.我发现它只能部分解决我的问题.在模型中删除不必要的引用修复了该问题.
| 归档时间: |
|
| 查看次数: |
3548 次 |
| 最近记录: |