c# - 后端没有错误,但 Ajax 功能失败
问题描述
我有一个 Ajax 调用和一个带有一些方法的控制器,但有些奇怪。
Ajax 调用可以到达Controller Method。该方法完美地返回值,没有错误,什么都没有。但是,在 AJAX 中,返回带有错误(不是 Ajax 成功)。
此外,如果我检查返回值,我可以在 responseJson 上看到正确的值,但状态为 404,statusText 为“error”({“readyState”:4,“status”:404,“statusText”:“error”})
有人知道发生了什么吗?后端没有错误,但是 Ajax 有错误。
控制器方法
public JsonResult SceneListUpdated(string sceneId)
{
SceneListModel model = new SceneListModel();
var licenseValidationState = KeygenLicenseState.CheckLicense();
if (licenseValidationState == 0)
{
SceneListService sceneService = new SceneListService();
model = sceneService.GetSceneListUpdated(sceneId);
return Json(new { Success = true, data = model }, JsonRequestBehavior.AllowGet );
}
return Json(new { Success = false, data = "" }, JsonRequestBehavior.AllowGet);
}
阿贾克斯函数
$.ajax({
url: "/api/test/SceneList/SceneListUpdated?sceneId=" + sceneIdAux, //Method in controller
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (e) {
},
error: function (data) {
}
});
解决方案
尝试修复ajax
$.ajax({
url: "/api/test/SceneList/SceneListUpdated/"+ sceneIdAux, //Method in controller
type: "GET",
success: function (e) {
},
error: function (data) {
}
});
也许您可以尝试其中一种路由,因为您有 404
[Route("{sceneId}")]
[Route("~/api/SceneList/SceneListUpdated/{sceneId}")]
public JsonResult SceneListUpdated(string sceneId)
推荐阅读
- apache-spark - spark udf 中的加密解密,使用 JKS 文件
- javascript - javascript reduce函数的意外行为
- django - Django 无法将关键字“AuctionListing”解析为字段。选项有:auctionitem、auctionitem_id、currentbid、id、usernameb、usernameb_id
- python - 加入流流错误:pyspark.sql.utils.AnalysisException:'流数据帧/数据集不支持多个流聚合
- python - Python中的QuantLib - 不能腌制'SwigPyObject'对象
- database - PostgreSQL - 连接到 localhost:"****" 拒绝错误
- c - 使用 GMP 获取数字的二进制后缀的最有效方法是什么?
- wordpress - 在本地主机上工作时需要 imagick 吗?
- angular - 如何在echarts条形图中手动强调系列?
- tensorflow - 如何在 LSTM 模型中屏蔽填充以进行语音情感识别