Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery & PHP - can I push from the server?

I am just starting to look at JQuery; until now everything has been PHP.

Just curious: if the server detects an event and wants to update the user's browser, can I do server push, or does the client have to poll?

like image 203
Mawg says reinstate Monica Avatar asked Nov 18 '10 03:11

Mawg says reinstate Monica


People also ask

What is jQuery?

jQuery is a small and lightweight JavaScript library. jQuery is cross-platform. jQuery means "write less do more". jQuery simplifies AJAX call and DOM manipulation. In this tutorial, you will get a lot of jQuery examples to understand the topic well. Let's see a simple jQuery example.

Why should I use jQuery UI?

Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice. What's New in jQuery UI 1.13?

Will jQuery work in all browsers?

Will jQuery work in all browsers? The jQuery team knows all about cross-browser issues, and they have written this knowledge into the jQuery library. jQuery will run exactly the same in all major browsers.

What are the features of jQuery library?

The jQuery library contains the following features: 1 HTML/DOM manipulation 2 CSS manipulation 3 HTML event methods 4 Effects and animations 5 AJAX 6 Utilities


2 Answers

Client has to poll, but you can do long polling, i.e. keep the request alive until the server has an event to push back (i.e. complete request).

Otherwise, you can use Web Sockets.

like image 156
alex Avatar answered Oct 19 '22 22:10

alex


The HTTP protocol works on the request-response principle which means that the server can only generate a response following a request from the client. This means that the server cannot send a response to the client without having received a request in the first place. This is not a PHP issue, it is an HTTP issue. So no, you can't push, the client has to make a request, or poll. You could take a look at long polling, as alex suggested.

like image 29
Alex Avatar answered Oct 19 '22 20:10

Alex