The goal is when a user visits the index route/ the JS code should create the post request then redirect to another url given by flask webapp
but when i uncomment i still get redirected but no post request is begin made
how do you redirect after the post request
A simple js function to check user info
<script type="text/javascript">
function lookup() {
const URL = '/route';
const xhr = new XMLHttpRequest();
$.get('https://www.cloudflare.com/cdn-cgi/trace', function(data) {
data = data.trim().split('\n').reduce(function(obj, pair) {pair = pair.split('=');
return obj[pair[0]] = pair[1], obj;
}, {});
sender = JSON.stringify(data)
xhr.open('POST', URL);
xhr.send(sender);
//console.log(data);
});
}
</script>
<body onload="lookup()"> </body>
<script type="text/javascript" > window.location.href = '{{x}}' ; </script>
Flask route
@UI.route('/' )
def index():
if request.method == "POST":
return render_template('index.html')
else:
return render_template('index.html')