I want to close my selectGroupView after getting response when I click on submit button. Currently I am not getting any response as my selectGroupView is closing suddenly whenever I click on submit button.
Actually I want to return a json data after submission of a form. So that I can use it further. Please Help me.
app.py
from flask import Flask, request,render_template
@app.route('/select-group/<string:assignerID>',methods=['GET'])
def selectGroupView(assignerID):
    assignerInfo = info.assignerInfo(assignerID,[])
        
    assignerID = assignerInfo['id']
    assignerName = assignerInfo['name']
    assignerGroups = assignerInfo['groups']
    return render_template('groups.html',groups = assignerGroups, assignerID = assignerID, assignerName=assignerName)
@app.route('/setup-group',methods=['POST'])
def setupGroupView():
    assignerID = request.form.get('assignerID')
    assignerName = request.form.get("assignerName")
    selectedGroup = request.form.get("group")
    selectedGroupID,selectedGroupName = selectedGroup.split(",")
    
    bot.sendTextMessage(assignerID,f'*{selectedGroupName}* Group Selected Successfully.')
    bot.sendTextMessage(assignerID,f'Please Wait')
    return '<h1>'I want to return Json'<h1>',200
groups.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Select Group</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='styles/style.css') }}">
</head>
<script>
    (function(d, s, id){
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/messenger.Extensions.js";
            fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'Messenger'));
    
    function handleSaveBtn(){
            MessengerExtensions.requestCloseBrowser(function success() {
          // webview closed
        }, function error(err) {
            console.log(err);
          // an error occurred
        });
        }
</script>
<body>
    <div class='head'>
        <img src="{{ url_for('static',filename='Image/logo.webp') }}" alt="Italian Trulli">
    </div>
    <div class="form">
        <form method="POST" action="/setup-group">
            <input type="text" hidden name="assignerID" id="psid" value="{{assignerID}}">
            <input type="text" hidden name="assignerName" id="psname" value="{{assignerName}}">
            {% for i in groups %}
            <input type="radio" id="{{i.group_name}}" name="group" value="{{i.group_id}},{{i.group_name}}">
            <label for="{{i.group_name}}"><b>{{i.group_name}}</b></label><br><br>
            {% endfor %}
        </br>
            <button type="submit" onclick="handleSaveBtn()">Save</button>
          </form>
    </div>
    
</body>
</html>
 
    