Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async getJSON(url, parameters){
- try{
- //check if URL isn't empty
- if(url.length == 0)
- return false;
- //construct HTTP parameters
- var params = '';
- for (var key in parameters) {
- if(params.length)
- params += "&";
- params += key + "=" + encodeURIComponent(parameters[key]);
- }
- //doing request
- const response = await fetch(`${url}${params}`);
- let body = await response.json();
- return body;
- }catch(err){
- console.error(err);
- return false;
- }
- }
- Promise {_40: 1, _65: 0, _55: null, _72: Handler}
- v
- _40:1
- _55:{success: false, msg: "segredo não informado"}
- _65:1
- _72:null
- __proto__:Object
- Promise.resolve(body).then(function(value) {
- console.log(value); //aqui deu log do JSON!
- body = value; // essa atribuição não funcionou, por algum motivo
- });
Add Comment
Please, Sign In to add comment