Answer the question
In order to leave comments, you need to log in
How to bind client side javascript function to server side event?
I apologize for the vague question, but this is the problem, that I can’t formulate it clearly for searching on Google or Stackoverflow.
There is a desire to write a page (HTML + JavaScript) that would respond to events occurring on the server. I know that there are ReackJS and similar frameworks that provide such functionality out of the box, but I would like to find an example in pure JavaScript on the client and PHP on the server.
What is the name of this technology, what requests to write to Google?
The simplest thing that comes to mind is a looping process on the client side with an AJAX request to the server. But it entails fast battery consumption on the mobile device and additional (paid) traffic in the case of mobile Internet, plus an empty server load.
Or maybe the "long way" (learn, install, apply framework a-la ReackJS) will be shorter than looking for/inventing a "simple" bike?
Thank you.
Answer the question
In order to leave comments, you need to log in
Why is everyone trying to connect a bunch of heavyweight frameworks?
Use Server Side Events, they are pretty easy to implement.
Read here:
learn.javascript.ru/server-sent-events
In general, it's better to read the entire section:
learn.javascript.ru/ajax
Do you need to update your data? No browser event? By timer? Then any technology will give the same effect.
I can advise PJax - read it, but I'm not sure that this is exactly what you need. Give an example of what you would like to receive? Updating data on a timer or what?
Thank you. it looks like socket.io is what can help me. However, in the very first example, it says that you need to install NodeJS. It looks like you can't do without an additional framework.
about clarifications from Maxim Timofeev
Do you need to update the data? on the client side - YES
Without an event in the browser? - YES
By timer? This is exactly what I'm trying to avoid.
Give me an example - practically it's a chat room
, I'll go and read about PJax
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question