I am making progress towards the solution, but I'm struggling with sending an HTTP POST method using Ajax. Understanding this will also be beneficial for my REST project.
While there are plenty of online resources available that use Jquery or Prototype js framework, I am interested in learning how to do it without relying on those frameworks.
<script type="text/javascript>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
var out;
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
out = xmlhttp.responseText;
alert(out);
}
}
xmlhttp.open("POST", "/resources/Inventory/2", true);
xmlhttp.setRequestHeader("Content-type", "application/jason");
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(null);
}
</script>
With traditional non-ajax POST (i.e. page reload or redirect), I can retrieve input values from HTML forms submitted by users on the server side.
However, I am unsure about how to access the values entered in input fields of an HTML form when using Ajax HTTP POST. Is it possible, or am I approaching this incorrectly?
<form method="post" action="">
<input type="text" name="info1" />
<button value="click to call js" onclick="loadXMLDoc()">
</form>