Angularjs 在angular/tornado网站上发布请求

Angularjs 在angular/tornado网站上发布请求,angularjs,tornado,Angularjs,Tornado,我在提出发帖要求方面有问题。下面的代码在用户尝试提交表单时失败,tornado handler.get_参数('login')和handler.get_参数('password')都返回无,而我清楚地发送了这些数据。更有趣的是,当我将方法从post更改为get时,一切都很好。如何使其与post请求一起工作 //angular js angular.module('playItApp', ['playItControllers', 'playItServices']); angular.modu

我在提出发帖要求方面有问题。下面的代码在用户尝试提交表单时失败,tornado handler.get_参数('login')和handler.get_参数('password')都返回无,而我清楚地发送了这些数据。更有趣的是,当我将方法从post更改为get时,一切都很好。如何使其与post请求一起工作

//angular js
angular.module('playItApp', ['playItControllers', 'playItServices']);

angular.module('playItServices', ['ngResource'])
    .factory('users', ['$resource', function($resource){
        return $resource('/api/user');
    }]);

angular.module('playItControllers', [])
    .controller('authentication', ['users', function(users){
        this.register = function(){
            users.save({'login': this.login, 'password': this.password});
        };
    }]);

# tornado handler
class User(JsonHandler):
    def post(self):
        login = self.get_argument('login')
        password = self.get_argument('password')
        user = self.db.create_user(login, password)
        self.set_secure_cookie('user', str(user['id']))
        self.write(user)

<div ng-controller="authentication as authentication">
    <h2>Registration</h2>
    <form>
        <input type="text" placeholder="login" ng-model="authentication.login">
        <input type="password" placeholder="password" ng-model="authentication.password">
        <button ng-click="authentication.register()">Register</button>
    </form>
</div>
//js
模块('playItApp',['playItControllers','playItServices']);
angular.module('playItServices',['ngResource']))
.factory('users',['$resource',function($resource){
返回$resource('/api/user');
}]);
角度模块('PlayitController',[])
.controller('authentication',['users',函数(users){
this.register=函数(){
保存({'login':this.login,'password':this.password});
};
}]);
#龙卷风处理机
类用户(JsonHandler):
def post(自我):
login=self.get\u参数('login')
password=self.get\u参数('password')
user=self.db.create\u用户(登录名、密码)
self.set\u secure\u cookie('user',str(user['id']))
self.write(用户)
登记处
登记
Angular(可能)将POST数据作为JSON发送,但
get_参数
用于表单编码数据。如果您想坚持使用json,您必须使用
json.loads(self.request.body)
而不是
get\u参数
,或者您应该能够使用Angular来发送表单编码数据。如果您关心与非javascript客户端的兼容性,您可能希望切换到表单编码数据,但是如果您对javascript的需求感到满意,那么使用JSON可能是更好的选择