setInterval not working for ajax call

荒凉一梦 提交于 2019-12-24 06:02:33

问题


I have a getJson call to a webservice and works fine, Now I'm trying to make the request every 10 sec. using setInterval with a callback function to fire an alert pop up. I can't make it work. Here's the code:

function ajxCall(){
   $.getJSON('http://api.tubeupdates.com/?method=get.status&lines=all&return=name,status,messages,status_starts&jsonp=?',
         function (result){
               $.each(result.response.lines, function(i, item){
                    $('#status').append("<p>"+item.name + " - " + item.status + " <br><b>" +item.messages + "</b> " + item.status_starts + "</p>");
               });
         }); 
    }

setInterval(ajxCall(), (10 * 1000), function(){
    alert('called!')
});

What am I doing wrong?

Thanks in advance,

Mauro


回答1:


 setInterval(function() {
      ajxCall();
   }, 10000);

Try that



来源:https://stackoverflow.com/questions/4323240/setinterval-not-working-for-ajax-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!