| 1 |
document.addEventListener('DOMContentLoaded', function () { |
| 2 |
var params = { |
| 3 |
action: 'tptn_tracker', |
| 4 |
top_ten_id: ajax_tptn_tracker.top_ten_id, |
| 5 |
top_ten_blog_id: ajax_tptn_tracker.top_ten_blog_id, |
| 6 |
activate_counter: ajax_tptn_tracker.activate_counter, |
| 7 |
top_ten_debug: ajax_tptn_tracker.top_ten_debug |
| 8 |
}; |
| 9 |
|
| 10 |
fetch(ajax_tptn_tracker.ajax_url, { |
| 11 |
method: 'POST', |
| 12 |
headers: { |
| 13 |
'Content-Type': 'application/x-www-form-urlencoded', |
| 14 |
'Cache-Control': 'no-cache' |
| 15 |
}, |
| 16 |
body: new URLSearchParams(params).toString() |
| 17 |
}) |
| 18 |
.then(function (response) { |
| 19 |
if (!response.ok && 204 !== response.status) { |
| 20 |
throw new Error('Tracker request failed'); |
| 21 |
} |
| 22 |
|
| 23 |
return response.text(); |
| 24 |
}) |
| 25 |
.then(function (data) { |
| 26 |
// handle the response data |
| 27 |
}) |
| 28 |
.catch(function (error) { |
| 29 |
console.error('Error:', error); |
| 30 |
}); |
| 31 |
}); |
| 32 |
|