更新一个div自动使用jQuery当新记录添加在MySQL数据库数据库、div、jQuery、MySQL

2023-09-10 13:23:24 作者:# 繁华落尽,谁是谁的

我在做一个社交网站,我的朋友。我想知道我怎么会包含更新的数据库,当一个新的记录在数据库中添加的少量插入记录的股利。总之,你一定看到了Facebook的实时通知,其淡入当有人做了。这一切都没有发生,整个现场通知div的清爽。只有新通知是prePEND到div。

I'm making a Social networking website for my friends. i wanted to know how i would Update a Div containing few inserted records of the database, when a new record is added in the database. In short you must have seen the live notifications of facebook, which fade in when someone does something . this all happens without the refreshing of the whole live notification div. only the new notification is prepend to the div.

我想做到这一点使用jQuery和AJAX,因为我对他们有很好的了解。和PHP作为服务器端语言。

I would like to do this using jquery and AJAX as i have good knowledge about them. and PHP as the server side language.

感谢你在前进。

PS:我已经搜查了许多网站的解决方案,但不可能在任何地方找到它。我甚至尝试去通过Facebook的来源$ C ​​$ C,但不可能找到它呢!我希望有人可以帮助我在这里! *的交叉手指的*

P.S : I have searched many websites for the solution, but couldnt find it anywhere. i Even tried going through facebook's Source code but couldnt find it there too ! I hope someone helps me here ! *crossed fingers*

推荐答案

基本上它是这样的:

创建你的页面上的JavaScript函数,使一个Ajax调用(用jQuery或本机XHR或什么不可以),以一个PHP页面。 PHP页面跟踪的新东西,并返回它调用的时候。 JS的功能,当接收数据时,添加新的标签(div的或其他)的通知栏。该函数被调用每一次用,而JavaScript的的setTimeout 的功能。

Create a javascript function on your page that makes an ajax call (with jquery or native xhr or what not) to a php page. The php page keeps track of "new stuff" and returns it when called. The js function, when receiving data, add new tags (divs or whatever) to the notification bar. The function is called every once in a while with javascript's setTimeout function.

如果其中的某些步骤是混乱,请你问一个更具体的问题。

If some of these steps are confusing to you please ask a more specific question.