diff --git a/script/send.js b/script/send.js index b7e3d3b..e8a84cd 100644 --- a/script/send.js +++ b/script/send.js @@ -3,11 +3,13 @@ var form = document.getElementById("formid"); function setresText(res) { document.getElementById("checker").innerText = res; } + form.addEventListener("submit", function (e) { e.preventDefault(); setresText("Sending msg.."); var msg = sendMessage(); }); + function isValid(email) { //check email is formated var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; @@ -25,24 +27,30 @@ function sendMessage() { return false; } - $.ajax({ - url: 'https://script.google.com/macros/s/AKfycbwkjI7POBip0D3idUWfZwmdN4bV9TPfkfUWLwWZbu_rxDWSM5_F5VI1jVAXCKlRt0ykAg/exec', - type: 'post', - data: $('#formid').serialize(), - success: function () { - //if form submited - setresText("Msg Sended !"); - setTimeout(function () { - formreset(); - }, 2000); - }, - error: function () { - //if form not submit - setresText("Somthing Error retry!"); - } - }); + var data = new FormData(); + data.set('Name','@PORTFOLLIO') + data.set('Email', email); + data.set('Request', message); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'https://script.google.com/macros/s/AKfycbwkjI7POBip0D3idUWfZwmdN4bV9TPfkfUWLwWZbu_rxDWSM5_F5VI1jVAXCKlRt0ykAg/exec', true); + + xhr.onreadystatechange = function(){ + if(xhr.readyState === 4){ + setresText("Message Sended !"); + setTimeout(function () { + formreset(); + }, 2000); + } + } + xhr.onerror = function(){ + setresText("Somthing Error !"); + } + xhr.send(data); + return true; } + function formreset() { //for empty all values setresText("");