ajax呼叫的烧瓶端点

问题描述:

我按住提交按钮的同时向我的服务器发出ajax呼叫。 按钮出现在页面http://127.0.0.1:5000/post/15ajax呼叫的烧瓶端点

jQuery函数调用,并在Python分别submit_comment端点定义:

function submit_comment(post_id) { 
    var uname = $('input[name="uname"]').val(); 
    var comment = $('textarea[name="comment"]').val(); 

    $.ajax({ 
     url: "/submit_comment", 
     data: {name: uname, comment: comment, post_id: post_id}, 
     method: "POST", 
     datatype: 'json', 
     success: function(response) { 
      console.log('reaches here');    
      addElement(response); 
      console.log('Is it me'); 
     }, 
     error: function(error) { 
      console.log('reached Error'); 
      console.log(error); 
     } 
    }); 
} 

PY

@main.route('/submit_comment', methods = ['POST', 'PUT']) 
def submit_comment(): 
    entry = request.get_json(force=True) 
    print 'comment:', entry 
    .... 

主要是蓝图。但我得到404错误。

127.0.0.1 - - [24/8/2017年10时30分55秒] “POST /后/ submit_comment HTTP/1.1” 404 -

我从那里这篇文章得到了追加到端点疑惑。 有人可以帮助我了解错误并解决它吗?

感谢, 迪帕克

+0

为什么你有一个PUT请求的例子吗? – SD3L

我不知道了很多,但我知道,在阿贾克斯瓶文档说来查询脚本根这样的:

$SCRIPT_ROOT = {{ request.script_root|tojson }}; 

,然后使用作为请求URL的一部分。

从我使用Ajax调用($.getJSON是一个jQuery功能$.ajax

$.getJSON($SCRIPT_ROOT + '{{ url_for("help_email") }}',