// URL Base do Servidor // var vServerURL = new String('https://docbiz.com.br/siso/scripts/'); // '-----------------------------------------------------------------------' // ' Função : ServerRequest() ' // ' Parâmetros : vURL -> String -> Parâmetros da URL de acesso ' // ' Retorno : String ' // ' Propósito : Executa o acesso remoto ao servidor via Ajax ' // '-----------------------------------------------------------------------' function ServerRequest(vURL, vSilent, method, postData) { var vReq; var vRet = new String(); vURL = 'https://docbiz.com.br/siso/scripts/AjaxRequest.aspx' + vURL; vReq = false; if (method == undefined || method == null || method == '') method = 'GET'; method = method.toUpperCase(); if (method != 'GET' && method != 'POST') method = 'GET'; if (postData == undefined || postData == '') postData = null; if (console) console.info('method: ' + method + ', postData: ' + postData); if (window.XMLHttpRequest && !(window.ActiveXObject)) { try { vReq = new XMLHttpRequest(); } catch(e) { vReq = false; } } else { if (window.ActiveXObject) { try { vReq = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { vReq = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { vReq = false; } } } } if (vReq) { vReq.open(method, vURL, false); if (method == 'POST') vReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); vReq.send(postData); vRet = vReq.responseText; } else { if (vSilent == undefined || vSilent == false) alert('Não foi possível criar o objeto XMLHttprequest() !\n\nURL : ' + vURL); vRet = ''; } if (vRet != '') { if (vRet == 'OK') { vRet = vRet + 'OK'; } if (vRet.substr(0,2) == 'OK') { vRet = vRet.substr(2,vRet.length - 2); } else { if (vURL.toLowerCase().indexOf('password=') > -1) { vURL = '*****'; } var vRetWithoutErrorWord = vRet || ''; if (vRetWithoutErrorWord.startsWith('ERRO')) { vRetWithoutErrorWord = vRetWithoutErrorWord.substring(4) }; if (vSilent == undefined || vSilent == false) alert(vRetWithoutErrorWord + '\n\nURL : ' + vURL); } } return(vRet); } // '-----------------------------------------------------------------------' // ' Função : ServerRequestAsync_SendAsync() ' // ' Parâmetros : ' // ' Retorno : String ' // ' Propósito : Executa o acesso remoto ao servidor via Ajax/async ' // '-----------------------------------------------------------------------' function ServerRequestAsync_SendAsync(vReq, method, vURL, postData) { return new Promise((resolve, reject) => { try { vReq.open(method, vURL, true); if (method == 'POST') vReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); var xhr = vReq; xhr.onload = (e) => { if (xhr.readyState === 4) { if (xhr.status === 200) { resolve(xhr.responseText); } else { reject(xhr.statusText); } } }; xhr.onerror = (e) => { reject(xhr.statusText); }; vReq.send(postData); } catch (err) { reject(err); } }); } // '-----------------------------------------------------------------------' // ' Função : ServerRequest() ' // ' Parâmetros : vURL -> String -> Parâmetros da URL de acesso ' // ' Retorno : String ' // ' Propósito : Executa o acesso remoto ao servidor via Ajax/async ' // '-----------------------------------------------------------------------' async function ServerRequestAsync(vURL, vSilent, method, postData) { var vReq; var vRet = new String(); vURL = vServerURL + 'AjaxRequest.aspx' + vURL; vReq = false; if (method == undefined || method == null || method == '') method = 'GET'; method = method.toUpperCase(); if (method != 'GET' && method != 'POST') method = 'GET'; if (postData == undefined || postData == '') postData = null; if (console) console.info('method: ' + method + ', postData: ' + postData); if (window.XMLHttpRequest && !(window.ActiveXObject)) { try { vReq = new XMLHttpRequest(); } catch(e) { vReq = false; } } else { if (window.ActiveXObject) { try { vReq = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { vReq = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { vReq = false; } } } } if (vReq) { vRet = await ServerRequestAsync_SendAsync(vReq, method, vURL, postData); } else { if (vSilent == undefined || vSilent == false) alert('Não foi possível criar o objeto XMLHttprequest() !\n\nURL : ' + vURL); vRet = ''; } if (vRet != '') { if (vRet == 'OK') { vRet = vRet + 'OK'; } if (vRet.substr(0,2) == 'OK') { vRet = vRet.substr(2,vRet.length - 2); } else { if (vURL.toLowerCase().indexOf('password=') > -1) { vURL = '*****'; } var vRetWithoutErrorWord = vRet || ''; if (vRetWithoutErrorWord.startsWith('ERRO')) { vRetWithoutErrorWord = vRetWithoutErrorWord.substring(4) }; if (vSilent == undefined || vSilent == false) alert(vRetWithoutErrorWord + '\n\nURL : ' + vURL); } } return(vRet); }