need to refresh the page content

孤街浪徒 提交于 2019-12-23 16:28:06

问题


I am using codeigniter frame work and currently working on social networking kind of stuff. My problem is, i need to notify the user of their friends activity with out reloading the page when the user clicks on the feeds link. I have tried the following script,

<script>
setInterval(function() {
$('#reload').fadeOut("slow").load('user_feeds').fadeIn("slow");
}, 10000);
</script>

It increases the load to my server. any other idea for accomplishing this.

Thanks in advance.


回答1:


Then try to decrease the time interval

<script>
 setInterval(function() {
 $('#reload').fadeOut("slow").load('user_feeds').fadeIn("slow");
 }, 1000);
</script>



回答2:


Manoj what you are trying to achieve here is notifications and the data source residing on the server, so there is no way you can do that from the browser either by a pull or push from the server.

pull you can achieve by constant polling / frequent polling - usually by setting a timeout and getting the notifications.

push - ideally not really push you can achieve this by combining AJAX+Comet, this can also be achieved by long polling too where you maintain a constant connection with the server for any new updates and return data to server when there is an update.

let me know if this helps or you need more information




回答3:


This is actually a very interesting problem, what you need is an implementation of COMET .There is an event routing bus using comet called COMETD. COMETD also has javascript implementation and has bindings for Jquery. http://cometd.org/documentation/2.x/cometd-javascript



来源:https://stackoverflow.com/questions/12596707/need-to-refresh-the-page-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!