Can somebody help me with ajax request to server? I'm trying to send data to server
static language(lang) {
const request = new Request("/change-language", {
method: 'POST',
body: JSON.stringify({lang: lang})
});
return fetch(request).then(response => {
return response.json();
}).catch(error => {
return error;
});
}
Function with ajax request
But this function doesn't work properly
Here jquery ajax request and he is works like expected
$.ajax({
type: 'POST',
url: '/change-language',
data: {lang: 'esp' },
success: function(data){
console.log(data)
}
});
any ways to make it work?
Thanks a lot!