mirror of
https://github.com/actix/examples
synced 2024-11-25 07:12:42 +01:00
20 lines
747 B
JavaScript
20 lines
747 B
JavaScript
|
function post(url = ``, data = {}) {
|
||
|
// Default options are marked with *
|
||
|
return fetch(url, {
|
||
|
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
||
|
mode: 'cors', // no-cors, cors, *same-origin
|
||
|
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json; charset=utf-8',
|
||
|
},
|
||
|
redirect: 'follow', // manual, *follow, error
|
||
|
referrer: 'no-referrer', // no-referrer, *client
|
||
|
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
||
|
}).then(response => response.json()); // parses response to JSON
|
||
|
}
|
||
|
|
||
|
// window.addEventListener('load', function() {
|
||
|
// console.log('All assets are loaded');
|
||
|
// console.log(getUrlVars());
|
||
|
// });
|