I'm studying JavaScript (without jQuery) and I try to get the response of a form submit.
Here is a (little modified) sample form example given on w3schools;
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>JavaScript FORMS Example #3</h1>
<br>
<h3>validating form</h3>
<form
name="myForm" action="http://www.w3schools.com/js/demo_form.asp"
onsubmit="return validateForm()" method="post">
Name: <input type="text" name="fname" required>
<input type="submit" value="Submit Form">
</form>
<br>
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if(x == null || x =="") {
alert("Name must be filled out");
return false;
}
}
</script>
</body>
</html>
What I am trying to do is to get the response of the submited form. The response can be a simple text, XML or JSON formatted. (Sure if the response is plain text, I can parse it with JSON.parse()
method)
I have searched/sweeped SO but all the answers regarding to the "getting response of the form submit" or similiar questions using jQuery, however, I am searching for an exact pure JavaScript solution.
Edit: The focus of the question is not making an AJAX call without jQuery. I'm simply asking for a possible simple solution if there is any.