1

I'm trying to have the newest messages pulled into the page on top. Currently the newest messages are going underneath each time a new message comes in.

<script>
if(typeof(EventSource)!=="undefined")
{
var source=new EventSource("sse/lup.php?");
source.onmessage=function(event)
{
document.getElementById("lup").innerHTML+=event.data;
};
}
else
{
document.getElementById("lup").innerHTML="Sorry, your browser does not support server-sent     events...";
}
</script>
4

2 回答 2

0

尝试这个。

<script>
if(typeof(EventSource)!=="undefined")
{
var source=new EventSource("sse/lup.php?");
source.onmessage=function(event)
{
document.getElementById("lup").innerHTML= event.data + document.getElementById("lup").innerHTML;
};
}
else
{
document.getElementById("lup").innerHTML="Sorry, your browser does not support server-sent     events...";
}
</script>

或在此处粘贴您的完整 html 代码。

于 2013-05-20T16:47:30.063 回答
0

你可能想要做类似的事情......

source.onmessage=function(event)
{
   var html = document.getElementById("lup").innerHTML;
   document.getElementById("lup").innerHTML = event.data + html;
};
于 2013-05-20T16:46:30.623 回答