Make AJAX call wait for event in php

半世苍凉 提交于 2020-01-13 05:09:05

问题


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.

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.

Thanks!


回答1:


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/
  • How do I implement basic "Long Polling"?
  • http://www.contentwithstyle.co.uk/content/long-polling-example-with-nodejs
  • http://www.zeitoun.net/articles/comet_and_php/start


来源:https://stackoverflow.com/questions/5088051/make-ajax-call-wait-for-event-in-php

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