AngularJS的http发布与angular和GAE - javascript

我需要一个小的解决方案。我只需要使用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) {

        });

    };

HTML:

{% 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) {

      });

使用php重新加载内容 - javascript

在对网站进行编程时,我以前使用过此代码,它可以完美工作,但是现在当我想使用一些Flash部件时,每次单击链接时,它都会重新加载所有网站。源代码: <!DOCTYPE html> <html> <head> <title>Hot King Staff</title> <meta charset=…

用jQuery填充模式形式 - javascript

我正在将订单表从数据库绘制到datatables(jquery插件)中。我要在每笔最后一笔交易或每笔交易中增加付款。问题是,如何获取单击添加付款按钮以添加付款的行的订单ID。其次,当点击addpayment时,它会弹出一个带有字段或订单号的模态表单。我想用在td中找到的订单ID填充该字段,并使其不可编辑或隐藏,但在提交模态表单时将其发布到服务器。表格和模式表…

保留文本区域的数据或值,然后选择输入 - javascript

通过$ _POST提交表单时,输入文件值仍然保留。像这样: if($_POST){ $error = false; if(!$post['price']){ $error = true; $error_note['price'] = "*Should not be empty"; } if($err…

带有AJAX和DOM处理API的下拉菜单 - javascript

我从API获取数据,但未在我的下拉菜单中显示。如果我用?act=showprovince回显,结果就在那里。example.html<head> <link rel="stylesheet" type="text/css" href="css/normalize.css"> …

尽管刷新,jQuery格式仍未应用于Ajax数据 - javascript

我正在通过GET响应消息从服务器(php文件)的可折叠内部加载列表视图。但是,尽管刷新了jQuery元素,但jQuery格式并未应用于添加的HTML。我的页面在这里:http://i.cs.hku.hk/~hsbashir/Project_Work/events/events.htmlHTML代码(仅相关代码)<script> lastRecor…