js的comet各个浏览器封装lib

作者: nick 分类: ajax, js, php 发布时间: 2011-03-19 12:43 ė 6没有评论

SimpleComet是一个轻量级的comet的封装类, 能智能的识别浏览器,应用不同的comet技术,在firefox浏览器上使用ajax,在IE、opera浏览器上使用htmlfile,iframe.

<script type="text/javascript">
// This function will be called every time the server pushes a new event.
function push(event) {
	// For this example, we simply show the excuse on the page.
	document.getElementById('excuse').innerHTML = event;
}
 
// This function will be called when/if the stream closes.
function disconnected() {
	// For this example we'll just show a nice message.
	document.getElementById('excuse').innerHTML = '<img src="img/arrow.png" alt="" title="" />'+
		' Click to see MORE reasons why this souldn\'t work!';
	document.getElementById('control').value = 'start';
}
 
// This function is executed when the button is clicked.
function toggle() {
	// First we check if the stream is open.
	if (!comet.active) {
		// Lets start streaming!
		comet.open('excuses.php', push, disconnected);
		document.getElementById('control').value = 'stop';
	} else {
		// Streaming is active, means the user wants to stop it.
		comet.close();
	}
}
</script>
 60) { continue; }
	// Finally, we push our excuse to the client.
	$comet->push($excuse);
	// 5 seconds delay before the next excuse.
	sleep(5);
}
 
?>
 60) { continue; }
	// Finally, we push our excuse to the client.
	$comet->push($excuse);
	// 5 seconds delay before the next excuse.
	sleep(5);
}
 
?>

simplecomet能监听出链接是否已经断了,是不是很智能,只要负责服务端的输出就行.
下载: http://www.mandor.net/files/simplecomet-1.0.zip

演示: http://mandor.net/2008/12/23/12-simplecomet-http-streaming-and-toilet-scrubbing

原文:http://www.cellphp.com/article-read-javascript-23-simplecomet-comet-javascript-php.html

本文出自 传播、沟通、分享,转载时请注明出处及相应链接。

本文永久链接: https://www.nickdd.cn/?p=1436

发表评论

您的电子邮箱地址不会被公开。

Ɣ回顶部