Can't get post ajax request data python

我的未来我决定 提交于 2020-01-15 14:26:14

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/28661576/cant-get-post-ajax-request-data-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!