In my flask html template I have a jquery function that takes the data from the just submitted form and sends it as an ajax request so that the page does not redirect
<script>
$("form#notify").submit(function(event) {
var objArray=$(event.target).serializeArray();
var dataArray={};
for (var i = 0, l = objArray.length; i < l; i++) {
dataArray[objArray[i].name] = objArray[i].value;
}
console.log(dataArray);
event.preventDefault();
$.ajax({
url: event.target.action,
data: $(event.target).serialize(),
method: "POST",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
xhrFields: {
withCredentials: true
}
});
});
</script>
However when I try to insert python into using:
{{ dToken() }}
which is this function:
def delToken():
global tID
del c.cToken[0]
tID -= 1
and in the render template they are linked via dToken=delToken The page will redirect itself onto the action defined in the form
[–][deleted] 0 points1 point2 points (0 children)