Can't get post ajax request data python

2019-08-12 20:15发布

I have html form:

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

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

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

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

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?

1条回答
在下西门庆
2楼-- · 2019-08-12 20:35

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

name=request.form['name']
data=request.form['phone'] 
查看更多
登录 后发表回答