Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********
- **
- **
- ** @author Victor Aurélio <victoraurelio.com>
- ** @since 2017, August
- **
- **
- ** @description this file have ajax functions
- **
- ********/
- // não fiz tratamento de erros para economizar tempo.
- let server = {
- //_url: 'http://victoraurelio.com',
- _url: 'https://quoti.com.br/node',
- //_url: 'http://localhost:9000',
- _port: '',
- _def: '/api/'+getAppName()+'/',
- url: function(route){
- return this._url + this._port + this._def + route;
- },
- request: function(type, url, data){
- return new Promise(function(resolve, reject) {
- let xmlHttp = new XMLHttpRequest();
- showIndicator();
- xmlHttp.addEventListener('load',function(){
- if(xmlHttp.status === 200){
- xmlHttp.responseJSON = JSON.parse(xmlHttp.responseText);
- hideIndicator();
- resolve(xmlHttp);
- }else{
- hideIndicator();
- reject(xmlHttp);
- }
- },false);
- xmlHttp.open(type, server.url(url), true);
- xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
- xmlHttp.setRequestHeader('transfer-encoding','gzip');
- xmlHttp.setRequestHeader('Authorization', 'Bearer ' + getToken());
- xmlHttp.send(JSON.stringify(data));
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement