SHARE
TWEET

Untitled

ovictoraurelio Feb 19th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********
  2.       **
  3.       **
  4.       **  @author Victor Aurélio <victoraurelio.com>
  5.       **  @since 2017, August
  6.       **
  7.       **
  8.       **  @description this file have ajax functions
  9.       **
  10. ********/
  11.  
  12. // não fiz tratamento de erros para economizar tempo.
  13.  
  14. let server = {
  15.     //_url: 'http://victoraurelio.com',
  16.     _url: 'https://quoti.com.br/node',
  17.     //_url: 'http://localhost:9000',
  18.     _port: '',
  19.     _def: '/api/'+getAppName()+'/',
  20.     url: function(route){
  21.         return this._url + this._port + this._def + route;
  22.     },
  23.     request: function(type, url, data){
  24.         return new Promise(function(resolve, reject) {
  25.             let xmlHttp = new XMLHttpRequest();
  26.            
  27.             showIndicator();
  28.             xmlHttp.addEventListener('load',function(){                
  29.                 if(xmlHttp.status === 200){
  30.                   xmlHttp.responseJSON = JSON.parse(xmlHttp.responseText);
  31.                   hideIndicator();
  32.                   resolve(xmlHttp);
  33.                 }else{
  34.                   hideIndicator();      
  35.                   reject(xmlHttp);
  36.                 }
  37.             },false);
  38.            
  39.             xmlHttp.open(type, server.url(url), true);
  40.             xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
  41.             xmlHttp.setRequestHeader('transfer-encoding','gzip');
  42.             xmlHttp.setRequestHeader('Authorization', 'Bearer ' + getToken());
  43.            
  44.             xmlHttp.send(JSON.stringify(data));
  45.         });
  46.     }
  47. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top