can anyone help me how to return javascript (values) array to flask admin route.we have to just return values,values2,values3 which are java script arrays to flask route named admin .please let if there are any changes in code. we are dynamically taking the values from the user and storing in values,values2,values3 javascript array now we need help to return these array to flask server with route name "/admin"
#flask route
@app.route('/admin',methods = ['POST','GET'])
def admin():
if request.method == "POST":
a=request.form.getlist("contacts[]")
return str(a)
#js code
window.onload = function(){}
var btn = document.querySelector("#btn");
btn.onclick = function(){
var div= document.createElement("div");
div.innerHTML = generateit();
document.getElementById("box").appendChild(div);
}
function generateit()
{
return "<input type='text' class='txt' placeholder='Enter party name' required> <input type='text' class ='txt1' placeholder = 'Enter region' required> <input type='text' class='txt2' placeholder='Enter name' required> <button id ='btn' onclick='removeit(this);'>Remove</button>";
}
function removeit(btn)
{
document.getElementById("box").removeChild(btn.parentNode);
}
values =[]
$.ajax({
url:'{{url_for("admin")}}',
type:'POST',
data:{contacts:values},
success:function(res){}
});
}
#HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<link href="form.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form >
<div id = "box" ><br><br>
<input type = "text" class="txt" placeholder="Enter party name" required>
<input type = "text" class="txt1" placeholder="Enter region" required>
<input type = "text" class="txt2" placeholder="Enter name" required>
<button id ="btn">ENTER DETAILS</button>
</div><br><br>
<div>
<button class = "sbtn" onclick = "data1(); data2(); data3()" >SUBMIT</button>
</div>
</form>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type = "text/javascript" src="/static/js/admin.js "></script>
</body>
</html>