I have a project that I made with jquery, it used ajax to call the server passing parameters through POST.
I have always seen the fetch but passing the parameters in Json format. I would like to do it by passing the parameters without it being Json. I'm trying like this...
const datos = {
username: username,
password: password
}
fetch('https://prs/react/login.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: datos
})
.then(function(datos) {
console.log('datos =', datos);
return datos;
})
You must use
JSON.stringify
to send the parameters.More info on how to use
fetch
here .