PHP - AJAX jQuery的服务器"推"系统 [英] PHP - AJAX jQuery Server "Push" System

查看:115
本文介绍了PHP - AJAX jQuery的服务器"推"系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个web应用程序,需要的生活的通知系统。如何设置我的服务器从一个MySQL数据库中提取数据,然后将其推到浏览器。我绝对知道如何做到这一点。如果有人可以帮助,这将是更AP preciated!太谢谢你了!

I am creating a web app that requires a live notification system. How would I set up my server to pull data from a mySQL database and then push it to the browser. I have absolutely NO idea how to do this. If anybody can help, it would be much appreciated! Thank you so much!

编辑:我也许应该更具体,我拉着数据作为XYZ最近创建了一个帐户,XZY最近......非常感谢

I should probably be more specific, I am pulling data as in XYZ recently created an account, XZY recently ... Thanks so much!

推荐答案

您不能把数据传送到浏览器,但你可以做的是建立自己的网页,以轮询服务器每隔几秒钟更新。一个例子设置是:

You cannot push data to a browser, but what you can do is set up your webpage to poll your server every few seconds for updates. An example setup would be:

从您的网站内,有一个计时器运行的JavaScript函数每隔几秒钟(或任何时间间隔为您的情况效果最好)。

From within your website, have a javascript function that runs on a timer every few seconds (or whatever interval works best for your situation).

开始在页面加载的定时器。

Start that timer on page load.

这javascript函数调用一个AJAX调用Web服务Web服务器(更多的是在第二个)上。

That javascript function invokes an AJAX call to a web service on your web server (more on that in a second).

在服务器端,您将需要某种形式的系统,可以追踪这些事件并把它们的地方,例如存储在带有时间戳的数据库表。因此,例如,当XYZ创建一个帐户,这将是在DB这个事件表记录。

On the server side you'll need some sort of system that tracks these events and stores them somewhere such as in a database table with a timestamp. So for example when XYZ creates an account, that would be logged in this "event" table in the db.

称为AJAX调用Web服务将运行在该表的查询和检索自上一次它被称为所有条目。然后,只需更新与这些结果的网页。

The web service called by the AJAX call will then run a query on that table and retrieve all entries since the last time it was called. Then just update the webpage with those results.

这显然不是100%的活,因为将根据您在JS计时器什么时间间隔设置在一个小的延迟,但它是pretty的接近。

It's obviously not 100% "live" as there will be a small delay depending on what time interval you set in the JS timer but it's pretty close.

这篇关于PHP - AJAX jQuery的服务器"推"系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆