无法获取后Ajax请求的数据蟒蛇蟒蛇、数据、Ajax

2023-09-10 20:23:48 作者:故人以北爱荒凉

我的HTML表单:

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

我有按钮,当我点击它,我做的AJAX POST请求:

I have Button and when I click it I am doing ajax post request:

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

在Chrome浏览器网页检查 我可以看到,数据被发送 NAME = + gfdsfd和放大器;手机= 89999

In chrome web inspector I can see that data is sent name=+gfdsfd&phone=89999

这是我使用的瓶,巨蟒我的后端功能:

This is my backend function I am using Flask,Python:

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

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

And it prints empty string in my console. What can be the problem?

推荐答案

要访问瓶的表格数据,你应该使用表格请求对象的属性。

To access Flask's form data you should use the form attribute of the request object .

name=request.form['name']
data=request.form['phone']