3

Let's say I have this setup

Why after clicking "arrToPython" button flask does not redirect me to "query_result.html"? And more importantly, how can I make it to do so?

I tried creating separate route like and using flask's "redirect" method, but it did not work for me either :( test.py:

from flask import Flask
from flask import request, url_for
from flask import render_template
from flask import redirect, Response


app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def savingImage():
    if request.method == 'GET':
        return render_template('test.html')
    if request.method == 'POST':
        return render_template('query_result.html')

if __name__ == '__main__':
    app.debug = True
    app.run()

Where test.html

<!DOCTYPE html> <html> <head>
    <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </head> <body>
    <input id="arrToPython" type=button value="arrToPython" href="result" onclick = "arrToPython()">
    <script type="text/javascript">
    function arrToPython(){
        var arr = ['one', 'two']
        $.ajax({
            type: 'POST',
            url: 'http://localhost:5000/',
            data: JSON.stringify(arr),
        }).done(function(){
            console.log('sent');
        })
    }

    </script> </body> </html>

And query_result.html

<br> Hola amigo!</br>
davidism
  • 121,510
  • 29
  • 395
  • 339

0 Answers0