Reputation: 4106
i need create web chat. So i need constantly refresh page.
I think use this jQuery function:
<script type="text/javascript">
$(document).ready(function(){
var sec = setInterval(function()
{
$('#chat').load('chat_r.php?id=' + Math.random());
}, 1000);
});
</script>
But I found out that this function is very slow.
Maybe you know a better option?
Upvotes: 0
Views: 442
Reputation: 14490
For your original question I would use
<meta http-equiv="refresh" content="1;url=http://example.com/" />
Though its a discouraged method it works fine for me. Basically just refreshes the page every second.
BUT for what your making(web chat) I would definitely use AJAX
Here is a snippet from one of my scripts
Ok stackoverflow won't work when I try to put the code in so I put the code on pastebin. http://pastebin.com/569zpbLe
Upvotes: 0
Reputation: 41533
why don't you try to use webSockets?
They're kind'of new and powerful.
Of course, there still are the old browsers which do not support many of the html5 new features, but, when I had to make a web app that used a web-chat, I ended up implementing both ajax and webSokcet based chat.
It's just a suggestion.
See documentation here.
Upvotes: 0
Reputation: 963
You should look into AJAX long polling. It will allow you to update the chat without refreshing the page, and will respond much more quickly than standard polling.
Upvotes: 5