It’s long ago I used xhr because there are much better alternatives since decades but if I remember right send is not accepting multiple arguments but you have to merge the arguments in one string
Don’t write out code for every possible field. If you had 30 form fields, would writing out (copy/pasting/overtyping) that code 30 times make sense?
Instead, use a general-purpose method that will get all the successful form field values at once, including file uploads, and will work for any number of forms on a page. Create a FormData object that references the current form that was submitted.
Add the following to any input or button that you are using to submit the form (or add an event listener to the page for the same element(s) to call the submit_form() function) -
onclick="return submit_form(this.form);"
And here’s a version of the submit_form() javascript function that happens to use a XMLHttpRequest object -
<script>
function submit_form(e)
{
// get all the 'successful' form data from the current form
var formData = new FormData(e);
// setup the ajax request
var xhr = new XMLHttpRequest;
xhr.open("POST", "save.php");
// display the text reply
xhr.onreadystatechange = function() {
if(xhr.readyState==4) {
alert(xhr.responseText);
}
}
// make the ajax request
xhr.send(formData);
// prevent the form from being submitted a second time
return false;
}
</script>
Long time since I did this type of form, but if the button is a submit button the form will be sent to the add_power_1.php file in the $__POST super variable.
It may need to be