让AJAX调用等待事件在PHP事件、AJAX、PHP

2023-09-10 16:53:59 作者:善恶都是我

我不知道如果我的瓦线是很清楚......我的问题是: 我有一个需要等待服务器上的事件JS应用。目前,它民调连续通过XMLHtt prequest服务器数据的每一秒。

I do not know if my tile line is clear enough... My problem is: I have a JS application that needs to wait for an event on the server. At the moment it polls continuous the server data via XMLHttpRequest every second.

我所想的是:是否可以进行呼叫等待,直到例如在PHP中改变一个变量

What I am thinking about is: Is it possible to make the call wait until for example a variable in PHP changes?

我希望我的问题是很清楚。

I hope that my question is clear enough.

谢谢!

推荐答案

您正在寻找长轮询 (俗称彗星)。上有SO和其他地方的许多例子。

You're looking for long polling (colloquially known as Comet). There are many examples on SO and elsewhere.

http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ 简单的长轮询的例子code? http://www.contentwithstyle.co.uk/content/long-polling-example-with-nodejs http://www.zeitoun.net/articles/comet_and_php/start http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ Simple "Long Polling" example code? http://www.contentwithstyle.co.uk/content/long-polling-example-with-nodejs http://www.zeitoun.net/articles/comet_and_php/start