const btn = document.querySelector('button');
const obj = {
name: 'John',
phone: +777723793,
street: 'Central',
};
btn.addEventListener('click', () => {
const xhr = new XMLHttpRequest();
xhr.open('POST', 'serv.php');
xhr.setRequestHeader("Content-type", "application/json");
const data = JSON.stringify(obj);
console.log(data);
xhr.send(data);
xhr.addEventListener('load', () => {
console.log(xhr.response);
});
});
const formData = new FormData();
for (const key in obj) {
formData.append(key, obj[key]);
}
...
xhr.send(formData);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
fetch
.