I want to perform my api call every 2000 milliseconds… I’m new in javascript and through the web I read that I can use setInterval()
method to execute a function every x seconds. But in my case it doesn’t work and my function is executed only once, and I don’t understand why and what it’s wrong.
My code is here:
<div class="col-1">
<div class="row fullrow">
<a class="show-your-reports" href="#" data-toggle="modal"
onclick="show_reports()"
data-target="#yourReportsDialog">
<script>
function show_reports(){
setInterval(function report_call(){
$.ajax({
type: 'GET',
url: api_url,
dataType: 'json',
success: function (data) {
# do some things...
}, 2000)
}
}
</script>
</a>
</div>
Thanks in advance!