Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
解析XMLjQuery并重复检查_Jquery_Xml_Parsing_Loops_Repeat - Fatal编程技术网

解析XMLjQuery并重复检查

解析XMLjQuery并重复检查,jquery,xml,parsing,loops,repeat,Jquery,Xml,Parsing,Loops,Repeat,现行代码 $.ajax({ type: "GET", url: "http://xSSHplusx.api.channel.livestream.com/2.0/livestatus.xml", dataType: "xml", success: function (xml) { var xmlDoc = $.parseXML(xml), $xml = $(xmlDoc);

现行代码

  $.ajax({
        type: "GET",
        url: "http://xSSHplusx.api.channel.livestream.com/2.0/livestatus.xml",
        dataType: "xml",
        success: function (xml) {


        var xmlDoc = $.parseXML(xml),
            $xml = $(xmlDoc);

    if($xml.find('ls:isLive').text()=='true'){
         player.load('SSHplus');
         }
         else{
            player.load('SaveStateHeroes');
           }
    }
});
我需要找到一种方法,每隔几秒钟重复此检查一次,以便在状态从false变为true时从XML输出中获取更新,以进行实际测试

var intervalId = window.setInterval(function() {
  // insert the code you wrote
  },
  5000 // or whatever number of milliseconds counts as "a few"
);
当您要停止检查时:

window.clearInterval(intervalId);

我会在
ajax
调用成功或出错后超时。此构造确保在前一个完成之前(网络拥塞)不会进行呼叫


如果您更具体地了解您想要了解的内容,您会得到更多响应我需要每5秒循环一次此代码,以检查xml何时更改播放机“频道”,但我似乎无法使其连续循环
function doYourThing() {
  $.ajax({
     type: "GET",
     url: "http://xSSHplusx.api.channel.livestream.com/2.0/livestatus.xml",
     dataType: "xml",
     success: function (xml) {
       var xmlDoc = $.parseXML(xml),
       $xml = $(xmlDoc);

       if($xml.find('ls:isLive').text()=='true'){
         player.load('SSHplus');
       } else{
         player.load('SaveStateHeroes');
       }

       setTimeout(function() {
          doYourThing();
       }, 2000); /* timeout in ms */

    }
  });
}