无法获得发布ajax请求数据python

时间:2015-02-22 18:28:57

标签: jquery python ajax forms python-2.7

我有html格式:

    <form id = "contactForm">
        <input type="text" name="name"></input>
        <input  type="text" name="phone"></input>
    </form>

我有Button,当我点击它时,我正在做ajax post request:

$.post( "/send-form", $('#contactForm').serialize()

在chrome web inspector中 我可以看到数据已发送 命名= + gfdsfd&安培;电话= 89999 enter image description here

这是我的后端函数我正在使用Flask,Python:

  @app.route("/send-form", methods=['POST'])
def send_form():
    name = phone = email = country = text = None
    data = request.data
    print request.data

它在我的控制台中打印空字符串。 可能是什么问题?

1 个答案:

答案 0 :(得分:2)

要访问Flask的表单数据,您应该使用请求对象的表单属性。

name=request.form['name']
data=request.form['phone'] 
相关问题