I have an a link tied to a refresh icon that calls a backend function to reload a section of the page and grab new results to display to the client end.
the function itself works just fine. I now want to automate it in JavaScript to fire off like every 30 seconds.
This is the current link I have:
<a data-ajax="post" data-ajax-callback="PagingCallBack" data-ajax-start="PagingStart" href="@Url.RouteUrl("Engagement", new { controller = "Campaign", action = "PageRefresh", queryID = Model.QueryID, campaignID = Model.CampaignID })" title="Refresh Row">
<img class="rowGrabber" src="/images/actions/refresh.png" height="20" width="20" alt="Refresh Row" title="Refresh Row" />
</a>
how would i take that and set it into a javascript function and call it every 30 seconds or so.
I looked at this response here and it's similar to what I'm looking for I just don't know the call syntax to make it work properly. How to fire AJAX request Periodically?
Add a way to identify your anchor tag (in this example add class="refresh-link" to you a tag or use your own class or id then simply use something like the following:
which will trigger the link every 30 seconds
window.setInterval(function() {
$(".refresh-link").trigger('click');
}, 30000);
Try using the setInterval
:
setInterval(function(){
//Your Ajax request or call your function here
}, 30000); //30000 is the number of milliseconds