Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
刷新javascript代码的步骤_Javascript_Jquery_Xml_Refresh_Setinterval - Fatal编程技术网

刷新javascript代码的步骤

刷新javascript代码的步骤,javascript,jquery,xml,refresh,setinterval,Javascript,Jquery,Xml,Refresh,Setinterval,很好,我有一个javascript,这要感谢这个站点,它来自一个XML文档,其链接是:,javascript必须删除艺术家姓名和歌曲XML文档的功能。 我打算做的是添加javascript代码来自动刷新艺术家姓名和歌曲 我尝试了,但没有得到这个结果,下面我将javascript保留为“尝试”刷新 <script type="text/javascript"> $(document).ready(function(){ /* Busca el archivo

很好,我有一个javascript,这要感谢这个站点,它来自一个XML文档,其链接是:,javascript必须删除艺术家姓名和歌曲XML文档的功能。 我打算做的是添加javascript代码来自动刷新艺术家姓名和歌曲

我尝试了,但没有得到这个结果,下面我将javascript保留为“尝试”刷新

<script type="text/javascript">
  $(document).ready(function(){
          /*  Busca el archivo NowOnAir.xml */
          $.ajax({
            type: "GET",
            url: "/NowOnAir.xml",
            dataType: "xml",
            success: function(xml) {
                /*Buscar el tag <Event> e ir repitiendo el proceso hasta el final (bucle) */
                $(xml).find('Event').each(function(){
                    /*Tomar los valores de startTime*/
                    var startTime = $(this).attr('startTime');

                    /*Buscar el tag <Song> y repetir bucle*/
                    $(this).find('Song').each(function(){
                        /*Tomar los valores de title*/
                        var title = $(this).attr('title');
                        var artist;

                        /*Buscar el tag <Artist> y repetir bucle*/
                        $(this).find('Artist').each(function(){
                            /*Tomar los valores de name*/
                            artist = $(this).attr('name');
                        });

                        /*Buscar el tag Expire y repetir bucle*/
                        $(this).find('Expire').each(function(){
                            var time = $(this).attr('Time');
                            $('.cancion').append("<p>"+artist+" - "+title+"</p>");
                            setInterval(function(){$('.cancion');}, 5000);
                        });
                    });
                });
            }
          });
        });
</script>
</head>
<body>
<div class="cancion"></div>
</body>
</html>

$(文档).ready(函数(){
/*Busca el-archivo NowOnAir.xml*/
$.ajax({
键入:“获取”,
url:“/NowOnAir.xml”,
数据类型:“xml”,
成功:函数(xml){
/*公共汽车终点站(bucle)*/
$(xml).find('Event').each(function(){
/*托马尔·洛斯瓦洛雷斯·德斯塔蒂姆酒店*/
var startTime=$(this.attr('startTime');
/*客车el tag y repetir bucle*/
$(this).find('Song').each(function(){
/*托马尔洛斯瓦洛雷斯酒店*/
var title=$(this.attr('title');
艺术家;
/*客车el tag y repetir bucle*/
$(this).find('Artist').each(function(){
/*托马尔洛斯瓦洛雷斯酒店*/
艺术家=$(this.attr('name');
});
/*客车el-tag到期,可重复使用*/
$(this).find('Expire').each(function(){
var time=$(this.attr('time');
$('.cancion')。追加(“”+artist+”-“+title+”

”); setInterval(函数(){$('.cancion');},5000); }); }); }); } }); });
我一定是弄错了,所以我来找你帮忙

既然已经非常感谢你了

  • 可能导致错误的主要原因是,
    右大括号和方括号
    在一些地方缺失

  • 使用
    setInterval
    功能自动刷新内容

    <script>
    
    $(document).ready(function(){
    get_info();
    setInterval(function(){ get_info(); }, 20000);
    
    function get_info(){
    
            $.ajax({
                type: "GET",
                url: "NowOnAir.xml",
                dataType: "xml",
                success: function(xml) {                     
                      $(xml).find('Event').each(function(){                                  
                      $(this).find('Song').each(function(){                
                      var title = $(this).attr('title');
                      var artist;                
    
                      $(this).find('Artist').each(function(){                    
                        artist = $(this).attr('name');
                      });                
    
                      $(this).find('Expire').each(function(){                    
                      $('.cancion').append("<p>"+artist+" - "+title+"</p>");
                    });
                  });
                });
              }
           });
    }
    });
    
    </script>
    
    并检查此示例:

    setInterval(函数(){
    $.ajax({
    网址:'http://api.icndb.com/jokes/random',
    方法:“GET”,
    beforeSend:function(){
    $(#content wr').children().fadeOut(1500);
    },
    成功:功能(数据){
    var val=data.value
    $(“#content wr”).append(“”+val.id+“”+val.joke+“”);
    }
    });    
    },5000);
    
    。新行>div{
    宽度:500px;
    空白:nowrap;
    溢出:隐藏;
    文本溢出:省略号;
    }
    
    
    如你所说,我再试了一次,但我无法得到我想要的,我可以按你所说的更改javascript,我将非常感激。谢谢@AndréSantos请检查我的答案中提供的
    代码片段
    。我把你提供的代码放在这里,我知道你的每一步都是很好的例子,但我仍然无法刷新,没有其他方法可以更简单地刷新?我编辑了这篇文章,基于我所缺少的代码来实现刷新,因为我使用了setInterval(函数(){所有内容disappears@Andr另一种方法是将
    放入
    中。这种方法将重新加载整个页面,而不仅仅是某些元素中的内容。
    $('#content-wr').html('<div class="new-lines"><div><a>' + val.id + '&nbsp;&nbsp;&nbsp;' + val.joke + '</a></div></div>');