<input type="file">
var data = JSON.stringify({ search: value });
var xhr = new XMLHttpRequest();
xhr.open( 'POST', url );
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.send( data );
xhr.addEventListener( 'readystatechange', function(){
if( xhr.readyState !== 4 ) return;
if( xhr.status === 200 ){
console.log( xhr.responsetext ); // ответ в консоль
} else {
console.log( xhr.statusText );
}
});
async () => {
const req = await fetch( url, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify({ search: value })
});
if( req.ok){
const res = await req.json(); // .text(), .blob()...
console.log( res ); // ответ в консоль
}
}