What is the difference between long Lling and normal ajax?

Asked

Viewed 605 times

3

I’m trying to understand more about long Polling to "manipulate" a site in real time, I’ve seen some videos and I’m thinking so far:

Let’s say I have an old date that’s in sql and I do an echo on it.

How long Polling will know if the old date will not be the same that it will fetch from time to time according to the setInterval function...?

Let’s say I want to display a blog post where all the text is in mysql, but suddenly I publish a new post, and whoever is on the page on the spot, will see the post on the spot ( Ava )So how does a long code know the difference between the old publication and the new one? Even not to conflict or repeat the same date saved in sql.

Remembering I don’t know anything about long Ping, so I might be asking bullshit...

1 answer

1


To use long-Polling in this specific context, the ideal is the page that makes long Polling receive a parameter that corresponds to the last timestamp that the user has.

With this, the page will make a query to the database to check if there are more recent posts, and if there are any, returns the information.

On the client side / browser, when you receive information from the long Polling page, you refresh the html content with the new information received, and call the long Polling page again with the timestamp of the information you just received.

I hope the text is not confusing :)

The difference is that instead of always making client-side ajax requests to see if there are new posts, you do an x in x seconds or minutes, and then the request is on the server side to check for new posts, and returns results if they appear.

  • I’m beginning to understand, but then the site owner will have to specify the parameters every day?

  • @Kevinmtk didn’t understand the question...

  • How do I not repeat the posts

  • @Kevinmtk if you need help should at least try to be more explicit. Repeat posts like? When? In what situation? What posts? Why are they repeated and where?

  • I don’t need help, I need to learn about long Polling > PHP > pulling mysql > index.php, there is a date that is already in mysql with echo $Row[... ], and if long can pull the same old dates that are already in mysql as just quoted in this comment?

  • How will I make you search for the date with last timestamp inserted in the last mysql id

  • @Kevinmtk As I said in my reply, after receiving the information from the most recent posts (through Javascript for example), we call back the page that returns the results, with a parameter that should be the ID or the date of the last post obtained, thus avoiding receiving duplicate information again. PS: This is a question and answer forum, where concrete questions are answered. To learn the language is studied and tutorials are sought on the subject.

  • Got it, P.S, I n understand reading pq on the net only have examples of what a situation I will never go through my life to study, so I prefer simple examples, that’s how I learned already html, css, php basics, js basics.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.