Is there a way to post form data using AJAX without relying on jQuery or other libraries?
I am looking to create an ajaxForm function that can serialize form data, make an AJAX post request, and then handle the response with JavaScript.
Let's say I have the following form:
<form action="url" method="POST">
<table>
<tr><td>label...</td><td><input name="input1" type="text"/></td></tr>
<tr><td>label...</td><td><input name="input2" type="checkbox"/></td></tr>
<tr><td>label...</td><td><select name="input3"><options....></select></td></tr>
</table>
</form>
If I select the form element using JavaScript and pass it along with a callback function to ajaxForm(form, callback), could someone provide an example of how this can be done? Thank you in advance.
Update: My main issue lies in figuring out how to serialize form data. Any suggestions are welcome!
Update Again: Thank you for all your responses. The problem has been resolved.
I have successfully converted the jQuery form plugin into pure JavaScript, and I'm excited to share it with all of you.
https://github.com/guileen/ajaxform.js
button.onclick = function(){
ajaxForm(form, function(xmlhttp){
alert(xmlhttp.status);
alert(xmlhttp.responseText);
});
}