每5秒钟在ajax中获取json数据

时间:2014-03-01 13:02:39

标签: ajax json

我有一个脚本每隔5秒发出一次json请求,但是我无法在success方法中显示警告。

javavascript是:

<script>
 function repite() {
     $.ajax({
          url: 'http://www.comparador.local/ProxmoxAPI/test.php',
          dataType: 'json',
          cache: false,
          success: function(data) {

            alert(data.test);
            },
            error: function(){
            }
         });

     setTimeout(repite,5000);
 }

 repite();
</script>

请愿结果:

{"test":0}

请愿书:

Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Cache-Control   no-cache
Connection  keep-alive
Host    www.comparador.local
Origin  null
Pragma  no-cache
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0

0 个答案:

没有答案