【发布时间】:2017-10-30 18:01:51
【问题描述】:
我正在使用 AspNetCore 中的 web 应用程序,我正在尝试通过 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);
}
}
和我的 ajax 调用:
$.get("/pack/GetPackWithAllCards", { packId: pack.packId }, function (pack) {
alert(pack);
});
我的错误总是一样的,我得到“加载资源失败:net::ERR_SPDY_PROTOCOL_ERROR”,状态 = 0
我的 api 正确返回一个包,但我的 ajax 调用没有得到它。
【问题讨论】:
-
它不工作
标签: jquery ajax asp.net-core