setInterval不适用于ajax调用 [英] setInterval not working for ajax call

查看:39
本文介绍了setInterval不适用于ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个到Web服务的getJson调用,并且工作正常,现在我试图每10秒发出一次请求.结合使用setInterval和回调函数来触发警报弹出.我不能使它工作.这是代码:

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!')
});

我在做什么错了?

预先感谢

毛罗

推荐答案

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

尝试

这篇关于setInterval不适用于ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆