I'm working on a project at the moment and was trying to use some AJAX to make submitting some smaller forms more smooth. I tried testing it by getting the "submit" button to just display text from a .txt file in a paragraph underneath it but that didn't work...
Here's my code:
<div style="color: #818181; width: auto; height 50vh; display:flex; flex-direction: row; justify-content: space-around;">
<div style="padding: 2vw; width: 35vw; height: 50vh; display: flex; justify-content: top; flex-direction: column; ">
<h2 style="color: #818181; margin: 0;">Contact</h2>
Questions? Go ahead.
<form method="post">
<p><input name='lcontactname' type="text" placeholder="Name" style="height: 5vh; width:28vw" required></p>
<p><input name='lcontactemail' type="text" placeholder="Email" style="height: 5vh; width:28vw" required></p>
<p><input name='lcontactsubject' type="text" placeholder="Subject" style="height: 5vh; width:28vw" required></p>
<p><input name='lcontactmessage' type="text" placeholder="Message" style="height: 5vh; width:28vw" required></p>
<p><input onClick='submitlContact' type='button' value='send' style="height: 5vh; width: 28vw; color: white;background-color:black; border: 2px white; padding: auto; font-size: calc(1vw + 0.5vh);" onClick='lcontactSend();'></p>
<p id='testpar'></p>
</form>
</div>
<script>
function submitlContact(){ //AJAX TO SUBMIT THIS FORM
//if (window.XMLHttpRequest) {
// code for modern browsers
xhttp = new XMLHttpRequest();
//} else {
// code for IE6, IE5
// xhttp = new ActiveXObject("Microsoft.XMLHTTP");
//}
xhttp.open("GET", "lcontactsubmit.txt", true);
xhttp.send();
document.getElementById("testpar").innerHTML = xhttp.responseText;
}
</script>
The idea is that when the button is pressed I can see the contents of the .txt file which has a random word in called lcontactsubmit.txt and definitely is saved to contain a random jumble of letters.
Any suggestions?
:)