9951 explained code solutions for 126 technologies


javascriptAjax post form (FormData) data with fetch


fetch('/backend.php', {
  method: 'post',
  body: new FormData(document.querySelector('form'))
}).then(function(r) {
  return r.json();
}).then(function(data) {
  console.log(data);
});ctrl + c
/backend.php

backend script to receive posted data

method: 'post'

set ajax request method to post

querySelector('form')

select form object that needs to be posted

return r.json()

server response will be processed as JSON

console.log(data)

replace with your code processing data (response from server as JSON object)