【问题标题】:Failed to load resource: the server responded with a status of 404 angularjs加载资源失败:服务器响应状态为 404 angularjs
【发布时间】:2015-04-16 20:37:49
【问题描述】:

我是角度新手 其他绑定工作正常,但 $https 调用不起作用 当我调用 http 调用时出现这样的错误

加载资源失败:服务器响应状态为 404(未找到) 我的脚本代码是

(function(angular) {
   var myApp = angular.module("myApp", []);
   myApp.controller('myTestController', function($scope, $http) {
     $scope.firstName = "Test";
     $http.get("Students/GetStudents").success(function(response) {
       $scope.firstName = response;
     });
   });
 })(window.angular); 

我的 API 控制器是:

[HttpGet]
public string GetStudents() {
    return "My Value";
}

【问题讨论】:

  • 你验证过url/资源路径正确吗?
  • 我有一个文件夹作为控制器,其中我有 api 控制器作为学生控制器。当我将此网址放入浏览器时,它会显示错误,例如:找不到资源。
  • 尝试创建一个包含一些内容的 .json 文件,并从 $http.get 调用它,而不是尝试调用控制器
  • 嗨,当我调用同一控制器的此方法时,它正在工作 [ResponseType(typeof(Student))] public IHttpActionResult GetStudent(int id) { Student student = db.Students.Find(id); if (student == null) { return NotFound(); } 返回好的(学生); } 抱歉编辑不佳
  • 不要将代码粘贴到评论中。 Edit your question.

标签: angularjs


【解决方案1】:

在 Api 控制器中: [HttpGet] [Route("getStudents")] public string GetStudents() { return "My Value"; }

在角度: 将“Students/GetStudents”更改为“Students/getStudents”

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 2016-11-01
    • 2018-01-29
    • 2020-07-04
    • 1970-01-01
    • 2019-07-04
    • 2021-11-20
    相关资源
    最近更新 更多