【问题标题】:Sails can't distinguish GET from POST in routes.js?Sails 在 routes.js 中无法区分 GET 和 POST?
【发布时间】:2016-04-03 20:53:00
【问题描述】:

我正在研究 Sails 并用它构建了一些简单的用户身份验证应用程序。路由写在 config/routes.js 中:

  'GET /signup': {view:'signup'},
  'POST /signup':'UserController.signup'

但是当我发出 POST 请求 localhost:1337/signup 时,我得到了响应(Chrome -> Network 显示)。不知道我在那里做错了什么。

你能帮帮我吗?

来自 api/controllers/UserController.js 的代码:

module.exports = {      
    signup: function(req, res){
            console.log('Please, be in console');
    }
}

角度代码:

angular.module('SignupMod').controller('SignupCtrl',['$scope', '$http', function($scope, $http){
  console.log('Signup Controller Started');

  $scope.runSignup = function(){
    console.log('Signing Up ' + $scope.name);

    //Submit to Sails Server
    $http.post('/signup', {
        name: $scope.name,
        email: $scope.email,
        password: $scope.password
    })
    .then(function onSuccess(response){
        console.log('Success!');
    })
    .catch(function onError(err){
        console.log('Error: ', err);
    })
  }
}])

【问题讨论】:

  • 你是通过ajax注册还是直接发帖???
  • Ajax 发布请求(通过 Angular $http.post)
  • 在网络中确实看到 post reqquest 或有 get 请求??
  • 最好在此处添加您的角度代码!
  • 角代码添加到问题。有谁知道我做错了什么?

标签: sails.js


【解决方案1】:

看起来这是在我的本地机器上安装了帆。

重新安装后,一切正常。 (在这两种情况下,我都在 npm 中安装了带有“-g”的sails)

【讨论】:

    猜你喜欢
    • 2016-09-24
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2011-02-20
    • 2011-10-30
    相关资源
    最近更新 更多