I just had the same problem, so I came up with something similar. All you have to do is add the code you need and assign the do_the_script function to the onclick event.
<script type="text/javascript">
var myIntv;
function do_the_script() {
var address='fancy_script.php';
var tmp = new XMLHttpRequest();
myIntv=setInterval(function(){
tmp.addEventListener("load", doneHandler, false);
tmp.open("POST", address);
tmp.send(null);
}, 1000);
}
function doneHandler(event) {
clearInterval(myIntv);
}
</script>
, , "" , 1 . , , , doneHandler . , , .