DOMContentLoaded', function() { var liveSourceLinks = document.querySelectorAll('.live_source a'); liveSourceLinks.forEach(function(link) { link.addEventListener('click', function(event) { // event.preventDefault(); // 阻止默认的链接跳转行为 // console.log("//" + window.location.host); var host = "//" + window.location.host; var xhr = new XMLHttpRequest(); xhr.open('GET', host + '/statistic/zhiboclick', true); xhr.responseType = 'json'; xhr.onload = function() { if (xhr.status >= 200 && xhr.status < 300) { // 请求成功时的回调函数 // console.log(xhr.response); } else { // 请求失败时的回调函数 // console.error('Request failed with status:', xhr.status); } }; xhr.onerror = function() { // 请求失败时的回调函数 // console.error('Request failed'); }; xhr.send(); }); }); });