@{
Layout = null;
}
Indexvar req = false;
var lastDelimiterPosition = -1;
$(document).ready(function () {
getData();
});
function getData() {
loadXMLDoc("/Comet/Test");
}
//新建一个XHR
function createRequest() {
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
req = new XMLHttpRequest();
} catch (e) {
req = false;
} // branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
req = false;
}
}
}
}
//发起请求
function loadXMLDoc(url) {
try {
if (req) {
req.abort();
req = false;
}
createRequest();
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send("");
} else {
alert('unable to create request');
}
} catch (e) { alert(e.message); }
}
//检查状态
function processReqChange() {
if (req.readyState == 3) {
try {
ProcessInput(req.responseText);
if (req.responseText.length > 3000) {
lastDelimiterPosition = -1; getData();
}
}
catch (e) {
alert(e.message);
}
}
}
//拆分字符串
function ProcessInput(input) {
var text = input;
var nextDelimiter = text.indexOf('|', lastDelimiterPosition + 1);
if (nextDelimiter != -1) {
var timeStamp = text.substring(nextDelimiter + 1);
if (timeStamp.length > 0) {
lastDelimiterPosition = nextDelimiter;
ProcessTime(timeStamp);
}
}
}
//输出 或者触发什么事件
function ProcessTime(time) {
document.getElementById('div1').innerHTML = time;
}