这个 AngularJS 调用上的接线松动在哪里

Where is the wiring loose on this AngularJS call?

本文关键字:在哪里 接线 AngularJS 调用 这个      更新时间:2023-09-26

我正在学习AngularJS,我相信我的页面有一根线松了。

该页面有一个文本区域,我在文本区域中输入了"aaa"。TEXTAREA 绑定到输入的 ng 模型。下面的 AngularJS 旨在监视来自外部的更改,并以一定的粒度将数据保存到服务器:

var UnixyTalk = angular.module('UnixyTalk', []);
UnixyTalk.controller('OutputController', ['$scope','$http', '$timeout', '$q',
   function($scope, $http, $timeout, $q)
        {
        var last_input = $scope.input;
        var repeatEr = function(data, status, headers, config)
            {
            var interval = !(config && config.time)? 1000 : 
            (1000 - (config.time - (new Date()).getTime()));
            angular.extend($scope, data);
            console.log(data);
            $timeout(function()
                {
                $http.post('/ajax/listen',
                    {
                    'cache': false, 
                    'params': {'conversation': 0},
                    'timeout': 1000,
                    }).success(repeatEr).error(repeatEr);
                $http.post('/ajax/say',
                    {
                    'conversation': 0,
                    'params': {'text': $scope.input, 'time': new
                      Date().getTime()}
                    });
                }, interval);
            }
        repeatEr();
        }
    ]);

服务器端报告它正在获取一个空的 POST 字典。

如果我想发布QUERY_STRING的键值对(即'field1=value1&field2=value2'而不是JSON对象),我应该如何列出字典?此代码中还有其他错误吗?

谢谢

由于您使用的是python,因此您可以创建一个函数来获取发布的数据,例如:

def getPost():
    if  'CONTENT_TYPE' in request.META and request.META['CONTENT_TYPE'].startswith('application/json'):
        return json.loads(request.body)
    elif request.method == 'POST':
        return request.POST.dict()

然后你可以调用该函数来获取你的后参数