简体   繁体   中英

Flask - Can i perform another request in the middle of an AJAX call.

So i have an ajax function in my javascript that posts to my flask backend.

Can I succesffuly make the call to /another_ajax_url ?

@app.route('/myroute', methods=['POST, GET'])
def test():
    a = 2 + 2
    requests.post('/another_ajax_url', data = a)
    #do the other stuff and return to /myroute
    b = 3 + 3
    return jsonify(b=b)

Yes, you can do that but you may prefer to use something like celery if you don't need the result.

Doing an http request inside the client request will block the client until the request is completed and the remaining of your code executed.

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