Created
May 11, 2015 17:32
-
-
Save SeavantUUz/61fccd4c1723146e490b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<script type="text/javascript"> | |
var evtSrc = new EventSource("/test"); | |
evtSrc.onmessage = function(e) { | |
console.log(e.data); | |
}; | |
function send(){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open("get", "/test", true); | |
xhr.send(null); | |
}; | |
</script> | |
</head> | |
<body> | |
<h1>Server sent events</h1> | |
<div id="event"></div> | |
<button onclick="send()">发送消息</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
去改用 xhr.onreadystatechange()
注意 xhr.readyState === 3
然后 newText = xhr.responseText.substr(上次文本长度)