Code cleanup
This commit is contained in:
@@ -1,24 +1,9 @@
|
|||||||
|
const request = ( url, params = {}) => {
|
||||||
const request = ( url, params = {}, method = 'GET' ) => {
|
|
||||||
let options = {
|
|
||||||
method
|
|
||||||
};
|
|
||||||
if ( 'GET' === method ) {
|
|
||||||
url += '?' + ( new URLSearchParams( params ) ).toString();
|
url += '?' + ( new URLSearchParams( params ) ).toString();
|
||||||
} else {
|
fetch( url );
|
||||||
options.body = JSON.stringify( params );
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetch( url, options ).then( response => response.json() );
|
|
||||||
};
|
};
|
||||||
|
const get = ( url, params ) => request( url, params);
|
||||||
|
|
||||||
const get = ( url, params ) => request( url, params, 'GET' );
|
|
||||||
|
|
||||||
|
|
||||||
// SQL test
|
|
||||||
function sendata(naam, score) {
|
function sendata(naam, score) {
|
||||||
get('https://oege.ie.hva.nl/~hossan/GetData.php', { name: naam, score: score } )
|
get('https://oege.ie.hva.nl/~hossan/GetData.php', { name: naam, score: score } );
|
||||||
.then( response => {
|
|
||||||
// Do something with response.
|
|
||||||
} );
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user