Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs http post与angular和GAE_Javascript_Python_Angularjs - Fatal编程技术网

Javascript angularjs http post与angular和GAE

Javascript angularjs http post与angular和GAE,javascript,python,angularjs,Javascript,Python,Angularjs,我需要一个小补丁。我只需要使用angularjs将我的数据(注释)发布到数据存储(GAE)中,但这还没有发生。以下angularjs“post”或html有什么问题 角度: $scope.addComment = function() { var form_comment = $scope.formFields.comment var payload = { comment: form_comment }

我需要一个小补丁。我只需要使用angularjs将我的数据(注释)发布到数据存储(GAE)中,但这还没有发生。以下angularjs“post”或html有什么问题

角度:

$scope.addComment = function() {

        var form_comment = $scope.formFields.comment

        var payload = {
            comment: form_comment
        }

        $http({
            method: 'POST',
            url: '/exp'
        }).then(function successCallback(response) {

            $scope.comments.push(payload);


        }, function errorCallback(response) {

        });

    };
{% extends "home.html"%}
{% block content %}


<div ng-controller="commentController" class="formcontent">
    <div class ="container">

            <form ng-submit="addComment()" method="post" id="frmComment">

                <textarea ng-model="formFields.comment" id="comment" name="commento" class="form-control status-box sameline" rows="2" placeholder="Recommend Colin"></textarea>
            </form>
            <div class="button-group pull-right sameline">
                    <p class="counter">140</p>
                    <button form ="frmComment"class="btn btn-primary" type="submit">Post</button>
            </div>
    </div>

    <div>
        <ul class="posts">
            <li ng-repeat = "c in comments">
                    {< c.comment >}
            </li>
        </ul>
    </div>

</div>
{% endblock %}
class expHandler(webapp2.RequestHandler):
    def get(self):
        title="Colin_MK: Experience"
        recommendations = Recommendation.query()
        self.response.out.write(json.dumps([rec.to_dict() for rec in recommendations]))
        template_vars = {'title': title, 'recommendations': recommendations}
        template = JINJA_ENVIRONMENT.get_template('/exp.html')
        self.response.out.write(template.render(template_vars))

    def post(self):
        r = json.loads(self.request.body)

        new_comment = Recommendation(comment=r['comment'])
        new_comment.put()

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/bio', bioHandler),
    ('/exp', expHandler)
], debug=True)
HTML:

$scope.addComment = function() {

        var form_comment = $scope.formFields.comment

        var payload = {
            comment: form_comment
        }

        $http({
            method: 'POST',
            url: '/exp'
        }).then(function successCallback(response) {

            $scope.comments.push(payload);


        }, function errorCallback(response) {

        });

    };
{% extends "home.html"%}
{% block content %}


<div ng-controller="commentController" class="formcontent">
    <div class ="container">

            <form ng-submit="addComment()" method="post" id="frmComment">

                <textarea ng-model="formFields.comment" id="comment" name="commento" class="form-control status-box sameline" rows="2" placeholder="Recommend Colin"></textarea>
            </form>
            <div class="button-group pull-right sameline">
                    <p class="counter">140</p>
                    <button form ="frmComment"class="btn btn-primary" type="submit">Post</button>
            </div>
    </div>

    <div>
        <ul class="posts">
            <li ng-repeat = "c in comments">
                    {< c.comment >}
            </li>
        </ul>
    </div>

</div>
{% endblock %}
class expHandler(webapp2.RequestHandler):
    def get(self):
        title="Colin_MK: Experience"
        recommendations = Recommendation.query()
        self.response.out.write(json.dumps([rec.to_dict() for rec in recommendations]))
        template_vars = {'title': title, 'recommendations': recommendations}
        template = JINJA_ENVIRONMENT.get_template('/exp.html')
        self.response.out.write(template.render(template_vars))

    def post(self):
        r = json.loads(self.request.body)

        new_comment = Recommendation(comment=r['comment'])
        new_comment.put()

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/bio', bioHandler),
    ('/exp', expHandler)
], debug=True)

post方法的签名如下所示:

post(url, data, [config]); 
因此,您还应该包括有效负载。试着这样做:

$http.post('/exp', payload).then(...)
此外,在promise的then()方法中,您应该发送对该方法的引用:

      .then(function(response) {
          $scope.comments.push(payload);
      }, function(response) {

      });

post方法的签名如下所示:

post(url, data, [config]); 
因此,您还应该包括有效负载。试着这样做:

$http.post('/exp', payload).then(...)
此外,在promise的then()方法中,您应该发送对该方法的引用:

      .then(function(response) {
          $scope.comments.push(payload);
      }, function(response) {

      });

很快谢谢@sabinstefanescu。。。学习曲线是陡峭的!我想让你指出我正在努力解决的下一个问题?在我的jinja2模板中获取评论。让我知道这很快,谢谢@sabinstefanescu。。。学习曲线是陡峭的!我想让你指出我正在努力解决的下一个问题?要在我的jinja2模板中获取评论,请告诉我