1

I have a simple webpage where a user can enter some text and send it to the backend using a post request:

<!DOCTYPE html>
<html>
  <head>
    ...
  </head>
  <body>
    <div class="container">
      <p>Enter your text:</p>
      <textarea id="mytextarea" rows="10" cols="80"></textarea>
      <br>
      <button type="button" id="button" class="btn btn-primary">Get results</button>
    </div>
  </body>

  <script type="text/javascript">

      $(document).ready(function(){
          $("button").click(function(){
              fetch("/api/get_results",
              {
                  method: "POST",
                  headers: {'Content-Type': 'application/json'},
                  body: JSON.stringify({text: document.getElementById("mytextarea").value}),
              })
          });
      });
  </script>
</html>

My backend uses Flask to recieve the text, process it and send a HTML page as response:

@app.route('/api/get_results', methods = ['POST'])
def get_results():
    #Extracting the arguments
    arguments = request.get_json()
    #processing ... ... 
    return render_template('response.html', content=content)

My question is: how do I get my browser to render the html page I'm sending?

user3091275
  • 1,013
  • 2
  • 11
  • 27

0 Answers0