function loadJSON(path, success, error) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { if (success) success(JSON.parse(xhr.responseText)); } else { if (error) error(xhr); } } }; xhr.open("POST", path, true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("referer=" + window.location.href); } function vote(sender) { loadJSON('https://tool.gollygoose.com/Tool/Vote', function(data) { debugger; if (data.HasError == true) { sender.outerHTML = '' + data.Error + ''; } else { sender.outerHTML = 'Thank For Expressing, Your Vote Is Now Part of The Overall Compassion Score'; var target = document.getElementById("result").children[0]; target.setAttribute("class", "score-" + data.Result.UserCompassion); setTimeout(function() { target.setAttribute("class", "animate score-" + data.Result.CompassionLevel); }, 5 * 1000); } }, function(xhr) { console.error(xhr); } ); } document.write(""); document.write('Vote');