解析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 */
}
});
}