Guest User

Untitled

a guest
Jun 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. async getJSON(url, parameters){
  2. try{
  3. //check if URL isn't empty
  4. if(url.length == 0)
  5. return false;
  6.  
  7. //construct HTTP parameters
  8. var params = '';
  9. for (var key in parameters) {
  10. if(params.length)
  11. params += "&";
  12.  
  13. params += key + "=" + encodeURIComponent(parameters[key]);
  14. }
  15. //doing request
  16. const response = await fetch(`${url}${params}`);
  17. let body = await response.json();
  18.  
  19. return body;
  20. }catch(err){
  21. console.error(err);
  22. return false;
  23. }
  24. }
  25.  
  26. Promise {_40: 1, _65: 0, _55: null, _72: Handler}
  27. v
  28. _40:1
  29. _55:{success: false, msg: "segredo não informado"}
  30. _65:1
  31. _72:null
  32. __proto__:Object
  33.  
  34. Promise.resolve(body).then(function(value) {
  35. console.log(value); //aqui deu log do JSON!
  36. body = value; // essa atribuição não funcionou, por algum motivo
  37. });
Add Comment
Please, Sign In to add comment