How can I avoid blocking other Ajax requests (requests in the same domain) on pages at the same time without long polling implemented by javascript-Ajax?

Source: Internet
Author: User
The implementation of long polling is obtained recursively using xmlhttprequest. Once the page is added with this polling method, ajax requests in other places will not respond, for example, rolling to the bottom of the page to automatically load new articles. I checked the information. It is said that HTTP1.1 does not allow clients to create two http requests to the same server at the same time... the implementation of long polling is obtained recursively using xmlhttprequest. Once the page is added with this polling method, ajax requests in other places will not respond, for example, rolling to the bottom of the page to automatically load new articles. After checking the information, it is said that HTTP 1.1 does not allow clients to establish two http connections to the same server at the same time. How can this problem be solved?

Reply content:

The implementation of long polling is obtained recursively using xmlhttprequest. Once the page is added with this polling method, ajax requests in other places will not respond, for example, rolling to the bottom of the page to automatically load new articles. After checking the information, it is said that HTTP 1.1 does not allow clients to establish two http connections to the same server at the same time. How can this problem be solved?

It is said that HTTP 1.1 does not allow clients to establish two http connections to the same server at the same time.

This statement is incorrect.

In fact, you cannot access the page where the session is used on the same site concurrently. Because the session is locked when you access page A, page B can be executed only after page A is released. The solution is to release the session immediately after the session is used (php uses session_write_close to release the session lock)

Once, once again

Directly terminate the round-robin and return the current result (the round-robin result may be blank). Initiate an ajax request from other places to get the result, and then enable a round-robin (maybe I thought it was too naive ), or change the requirement.

In fact, server push is implemented by means of polling (this is generally the role ?), It is better to use socket, but it seems that its standards are not too clear. For details, please google. By the way, I also saw an article shared yesterday: Technical Design of the message push mechanism.

Recursion LongPolling. When the second request is enabled, the connection of the first request has been closed. There is actuallyOneAvailable channels. As long as the data service corresponding to the backend returns fast enough, a channel can be left empty.

For other solutions, place some Ajax in other domains and configure the server CORS or iframe.

How to submit ifame data

Iframe actually uses form to submit data to an iframe, and then returns a page in iframe, which contains a piece of js Code.
For example

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.