var urlstuncrm = "https://api.stuncrm.com/"; var urlAtual = window.location.href; var urlClass = new URL(urlAtual); var search = ""; if(urlClass.search != ""){ search = "&"+urlClass.search.replace("?", ""); } function serialize(form){ if(!form||form.nodeName!=="FORM"){return } var i,j,q=[]; const replaceSpecialChars = (str) => { return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // Remove acentos .replace(/([^\w]+|\s+)/g, '-') // Substitui espaço e outros caracteres por hífen .replace(/\-\-+/g, '-') // Substitui multiplos hífens por um único hífen .replace(/(^-+|-+$)/, '') // Remove hífens extras do final ou do inicio da string .toLowerCase(); } var title; if(form.getAttribute("title") !== null){ title = form.getAttribute("title"); }else if(form.getAttribute("id") !== null){ title = form.getAttribute("id"); }else{ title = document.title; } q.push("title=" + encodeURIComponent(replaceSpecialChars(title))); //Array de parametros 'chave=valor' var params = window.location.search.substring(1).split('&'); for(var i=0; i < params.length; i++) { var param = params[i].split('='); q.push(param[0]+"=" + param[1]); } const data = new FormData(form); const queryString = new URLSearchParams(data).toString(); return q.join("&")+"&"+queryString; }; document.addEventListener('submit', function(event){ if (event.target && event.target.tagName === 'FORM') { let data = serialize(event.target), url = urlstuncrm + "trackingcode?origem=" + encodeURI(urlClass.origin) + search + "&token=li8PLcFvy0Umr&" + data; let xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status = 200){ console.log(xhr.responseText); } } } xhr.send(); } });