【发布时间】:2021-05-07 03:38:01
【问题描述】:
我确定这个问题之前已经发布过很多次,并且我已经查看了所有相关主题。但是还是不行。
我们有 JavaScript 部分:
$.ajax({
type: "GET",
url: "https://localhost:44346/api/persons/",
//dataType: "JSON",
success: function (response) {
callback("a");
},
error: function (response) {
callback("b");
}
}
);
还有 C# 部分:
[Route("persons")]
[HttpGet]
public ActionResult GetPersons()
{
return new JsonResult(new { Success = true, Result = "abc" },
System.Web.Mvc.JsonRequestBehavior.AllowGet);
}
问题是 Jquery 总是有 result = "b" 的错误。 Api 中的断点被命中。我试过有无dataType: "JSON"。将参数发送到 Api 也可以,但返回结果不起作用。所有项目都是 .Net 5.0。
【问题讨论】:
-
获取响应的详细信息会很有帮助。尤其是状态代码和任何错误消息。
-
请也发布控制器标题
-
response.statusCode.toString() 给出: f u n c t i o n ( e ) { v a r t ;我 f ( e ) 我 f ( h ) T 。 a l w a y s ( e [ T . s t a t u s ] ) ; e l s e f o r ( t i n e ) w [ t ] = [ w [ t ] , e [ t ] ] ; r e t u r n t h i s }
-
控制器头:´[ApiController] [Route("api")] public class PersonController : ControllerBase {´
标签: javascript c# jquery model-view-controller