Javascript-how can I retrieve updated data from the database when I use Server-SentEvents?

Source: Internet
Author: User
I think of two methods: 1. if any data is returned from the last time period, chrome can use the last 3 seconds, but Firefox uses the last 5 seconds, firefox often fails to fetch data. chrome will retrieve repeated data in five seconds. 2. second... I think of two ways:
1. if any data is returned from the last time period, chrome can use the last 3 seconds, but Firefox uses the last 5 seconds, firefox often fails to fetch data. chrome will retrieve repeated data in five seconds.

2. the second approach is to mark the database as read. However, because different browsers do not synchronize the data obtained from different terminals, one of them is marked as read after obtaining the data, other browsers cannot obtain the data.

So what should we do?

Reply content:

I think of two methods:
1. if any data is returned from the last time period, chrome can use the last 3 seconds, but Firefox uses the last 5 seconds, firefox often fails to fetch data. chrome will retrieve repeated data in five seconds.

2. the second approach is to mark the database as read. However, because different browsers do not synchronize the data obtained from different terminals, one of them is marked as read after obtaining the data, other browsers cannot obtain the data.

So what should we do?

The second approach is acceptable, but to optimize it, you can obtain the latest data update time from the server in the table memory and the terminal time is smaller than the table time, it indicates that new data needs to be pushed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.