9951 explained code solutions for 126 technologies

javascriptAjax post x-www-form-urlencoded data

fetch('/backend.php', {
  method: 'post',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
  body: 'var1=' + encodeURIComponent('Donald Trump :(') + '&var2=123'
}).then(function(r) {
  return r.json();
}).then(function(data) {
});ctrl + c

backend script to receive posted data

method: 'post'

set ajax request method to post

headers: { 'Content-Type'

sets x-www-form-urlencoded data encoding


pass encoded variables and values separated by &


name of first variable to post

'Donald Trump :('

value of var1 variable to post which needs to be encoded

return r.json()

server response will be processed as JSON


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