简体   繁体   中英

Can't get post ajax request data python

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=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'] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM