I'm calling an internal web page to my div every second with setInterval (that is to say reloading div). It's working fine but users should click a button inside of that reloading div and it fails.
This is my code:
HTML:
<ul class="folio-list" id="buttons"></ul>
JavaScript:
<script type="text/javascript">
window.onload = function() {
setInterval(function(){ $("#buttons").load("<?php echo site_url('buttons'); ?>"); }, 1000);
};
</script>
And this is the calling page's HTML:
<li class="tile-large pink">
<div id="time">
<h2 class="Hours">30 Minutes </br> 1 BTC</h2>
<br />
<div class="timer">
<div class="col-xs-4">
<div class="form-group">
<input type="text" class="form-control" id="hrs" value="0">
<label for="firstname" class="col-sm-2 control-label">Hrs</label>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<input type="text" class="form-control" id="mnt" value="0">
<label for="firstname" class="col-sm-2 control-label">Mnt</label>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<input type="text" class="form-control" id="sec" value="0">
<label for="firstname" class="col-sm-2 control-label">Sec</label>
</div>
</div>
</div>
<br />
<h3 class="winner-name"> Nobody </h3>
<button class="btn btn-success pay" data-id="2">Get Ticket!</button>
</div>
</li>
I'm trying to make this part clickable
<button class="btn btn-success pay" data-id="2">Get Ticket!</button>
with this JavaScript code below:
<script type="text/javascript">
$('.pay').click(function() {
var id = $(this).attr('data-id');
$.ajax({
url: "<?php echo site_url('pay'); ?>" + "/" + id,
type: 'POST',
success: function(answer) {
$('#answer').html(answer);
}
});
});
</script>
When I disable reloading thing, button working fine. I'm sure that the problem is setInterval part.
Thanks in advance.