Why is my code not sending the data to server ? It does display the data into the console but doesn't seem to be sending anything.
document.querySelector("form").addEventListener("submit", function (e) {
e.preventDefault();
var formData = {
"name": e.target.elements.name.value,
"author": e.target.elements.author.value,
"link": e.target.elements.link.value
}
var req = new XMLHttpRequest();
req.open("POST", "http://localhost/javascript-web-srv/post_form.php", true);
req.setRequestHeader("Content-Type", "application/json");
req.send(formData);
formData = JSON.stringify(formData);
console.log(formData);
});
req.send(JSON.stringify(formData));formDatais a plain object, not an array.