2012-03-01 51 views
0

这个脚本后仍连接显示正确的结果只有一次,然后在浏览器仍然是“正在连接...”如何显示阵列 - 浏览器第一次加载

$(document).everyTime(1000, 'controlled', function() { 
    $.ajax({ 
     type: 'GET', 
     url: 'sisplits2.log', 
     dataType: 'text', 
     async: 'false', 
     success: function(data){ 
     array = data.split('-'); 
     } 
    }); 
}); 

$(document).everyTime(1000, 'controlled', function() { 
    var j = array.length; 
    var i = 0; 
    $('#vory').html(function(){ 
     while (i<j){ 
     document.write(array[i]); 
     document.write("<br />"); 
     i++; 
     } 
    }); 
}); 
+1

载入后无法载入document.write – charlietfl 2012-03-01 00:59:16

回答

0

我不明白为什么你有两个定时器在这里循环。为什么不在你的回调函数中做所有的打印?

此外,如问题的注释中所述,document.write在页面加载后无效。取而代之的是,使用jQuery附加/替换到您#vory元件:

$(document).everyTime(1000, 'controlled', function() { 
    $.ajax({ 
     type: 'GET', 
     url: 'sisplits2.log', 
     dataType: 'text', 
     async: 'false', 
     success: function(data){ 
      array = data.split('-'); 
      $('#vory').html(''); // Clear contents 
      for(var i in array) { 
       $('#vory').append(array[i]+'<br>'); 
      } 
     } 
    }); 
}); 

实施例:http://jsfiddle.net/j6WuV/1/

的例子是类似的,有用于的jsfiddle修改和使用的setInterval代替everyTime的。

相关问题