【问题标题】:Sailsjs 404 (Not Found) api rest deleteSailsjs 404(未找到)api休息删除
【发布时间】:2016-09-07 13:48:42
【问题描述】:

HTML

当我尝试删除一些数据时,我在控制台中得到这个:当我尝试删除一些数据时,我在控制台中得到这个:当我尝试删除一些数据时,我在控制台中得到这个:当我尝试删除时我在控制台中得到了一些数据:

 DELETE https://sails-backoffice.herokuapp.com/api/todo/:id 404 (Not Found)

有什么想法吗?

<tbody>
          <tr ng-repeat="todo in listTodo">
            <td>{{$index}}</td>
            <td>{{todo.id}}</td>
            <td>{{todo.titre}}</td>
            <td ng-class="{'completed': todo.completed == true}"><a href="/message-details/{{todo.id}}">{{todo.message}}</a></td>
            <!--<td><button type="button" class="btn btn-primary">Ajouter</button></td>-->
            <td><button type="button" class="btn btn-danger" ng-click="delete(todo.id)">Supprimer</button></td>

          </tr>
        </tbody>

控制器

angular.module('crud')
  .controller('TodoCtrl', function ($scope,$routeParams,Todolist,$http,Todo) {
      $scope.delete=function(id){

                var removed=Todo.removeTodo(id);

            removed.success(function (data, status, headers, jwr) {

                  $scope.listTodo=data;


          })
          .error(function (data, status, headers, jwr) {



              console.log(data);

          });

          };  });

服务

angular.module('crud')
  .service('Todo', function ($http) {
 removeTodo:function(id){

            return $http.delete('https://sails-backoffice.herokuapp.com/api/todo/:id',id);
        },

  });

【问题讨论】:

    标签: angularjs node.js http sails.js


    【解决方案1】:

    如果您使用的是蓝图 api,请通过删除 'api' 来尝试此操作

    return $http.delete('https://sails-backoffice.herokuapp.com/todo/:id',id);
    

    否则 你需要在 config/route.js 中定义路由

    【讨论】:

      【解决方案2】:

      DELETE 是一个 HTTP 动词,这意味着您使用 JQuery 向 /api/todo/:id 路由发送 AJAX 请求。如果你还没有为sails.js 的config/routes 文件配置该路由,它会发回这个404。

      我建议通读sails documentation 关于路线的信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-17
        • 1970-01-01
        • 2019-05-03
        • 1970-01-01
        • 1970-01-01
        • 2020-04-12
        • 2021-09-15
        • 2018-08-26
        相关资源
        最近更新 更多