Strobe_
Strobe_

Reputation: 515

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)

Upvotes: 0

Views: 41

Answers (1)

User2342342351
User2342342351

Reputation: 2174

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.

Upvotes: 1

Related Questions