如何在PHP + Javascript/jQuery上实现观察者模式? [英] How do I implement observer pattern on PHP + Javascript/jQuery?
问题描述
就像在SO中回答一个问题一样,如果有人回答了这个问题,就会出现一条通知(通过AJAX吗?).我唯一重复此方法的方法是在脚本中包含一个超时,该超时在每n秒更新一次时获取.有没有办法在PHP + Javascript(带有jQuery)上使用观察者模式来做到这一点?
您必须查看 COMET 方法.>
根据维基百科 反向Ajax是指Ajax设计
使用长期HTTP的模式
连接以实现低延迟
Web服务器与
浏览器.基本上,这是一种
从客户端向服务器发送数据,以及
推送服务器数据的机制
回到浏览器. 我建议您实施以下方法,这很容易实现.我以stackoverflow回答为例. 希望这会有所帮助. Just like in SO, where one is answering a question, if somebody has answered said question, a notification will appear (via AJAX?). My only way of somewhat replicating this is by including a timeout on my script that fetches if there is an update every n seconds. Is there a way to do this using observer pattern on PHP + Javascript (w/ jQuery)? you have to look at the ReverseAJAX or COMET methodologies. As per wikipedia Reverse Ajax refers to an Ajax design
pattern that uses long-lived HTTP
connections to enable low-latency
communication between a web server and
a browser. Basically it is a way of
sending data from client to server and
a mechanism for pushing server data
back to the browser. EDIT: i suggest you to implement the following approach, this is simple to implement. I take stackoverflow answering as an example. Hope this helps. 这篇关于如何在PHP + Javascript/jQuery上实现观察者模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!