I'm trying to use the below snippet to capture the HTTP response of the form request and display the response in the browser. But clicking for Submit button navigates me away from my website.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form name="responseHere" action="https://www.stackoverflow.com/">
<input type="submit" value="Submit request" />
</form>
<script type="text/javascript">
var responseHere = document.getElementById("responseHere").value;
alert(responseHere)
</script>
</body>
</html>
I've also tried XHR methods to perform GET requests, but receive a CORS error when attempting to query domains outside my website's domain.
Is it possible to capture the HTTP response from the form submission and pass it to alert()
or console.log()
in Javascript?