Jqueryabort bug, ie Long polling bug

Source: Internet
Author: User
Recently, the company's project needs to do some webim research and found the following three problems during the demo test: 1. uninterrupted long polling of requests, when refreshing the page on IE, the page will get stuck. 2. The initial estimate is that the number of ie requests is limited. Therefore, before the page is uninstalled, the request is processed by abort (),... syntaxHighlighter. all ();

Recently, the company's project needs to do some web im research and found the following three problems during the demo test:
1. uninterrupted long polling requests. When refreshing the IE page
2. The preliminary estimation is that the number of ie requests is limited. Therefore, before the page is uninstalled, the request is processed in abort (), but an error is reported. The result shows that the object does not support this method.
3. ff and chrome will automatically interrupt the request when refreshing the page and execute the success callback.
For the second problem, I checked some information and summarized the bug of jquery abort in ie7. The solution is as follows:
Open the jquery source file and find the following code:
1. try {
2. var oldAbort = xhr. abort;
3. xhr. abort = function (){
4. if (xhr ){
5. oldAbort. call (xhr );
6 .}
7. onreadystatechange ("abort ");
8 .};
9.} catch (e ){}
Replace
1. try {
2. var oldAbort = xhr. abort;
3. xhr. abort = function (){
4. if (xhr ){
5. if (oldAbort. call === undefined ){
6. oldAbort ();
7.} else {
8. oldAbort. call (xhr );
9 .}
10 .}
11.
12. onreadystatechange ("abort ");
13 .};
14.} catch (e ){}
OK, the bug of jquery abort is fixed!
This BUG is fixed. the problem persists when the system is released for testing! Still stuck!
The request is written in this way.
1. function queryMsg (){
2. ajaxquery = $. ajax ({
3. type: "get ",
4. url: "http: // 192.168.94.26/feed/subscribe ",
5. cache: false,
6. success: function (data, textStatus ){
7. if (data ){
8. // processing result
9 .}
10. queryMsg (); // continue the new request
11 .}
12 .});
13 .}
Solution:
Replace queryMsg () with setTimeout (queryMsg, 0)
OK, solved!
The preceding two operations are indispensable.
In addition, when ff and chrome are unloaded on the page, persistent connections that have not been requested to complete will be forced to switch to the success status, that is, the success event in ajax will be triggered when the page is refreshed, the same problem will occur after ie adds abort (), so special processing is required for this problem. In my case, add a Switch Parameter and assign values to the switch parameter through the onbeforeunload event.
Complete code:
1. // Switch
2. var _ flag_is_unload = false;
3. // request variable
4. var ajaxquery = null;
5. // query the message
6. function queryMsg (){
7. ajaxquery = $. ajax ({
8. type: "get ",
9. url: "http: // 192.168.94.26/feed/subscribe ",
10. cache: false,
11. success: function (data, textStatus ){
12. if (! _ Flag_is_unload ){
13. if (data ){
14. // process the message
15 .}
16. setTimeout (queryMsg, 0 );
17 .}
18 .}
19 .});
20.
21 .}
22. function funBeforeunload (){
23. // abort the request
24. ajaxquery. abort ();
25. // Switch Status
26. _ flag_is_unload = true;
27 .}
Summary:
1. When the page is unloaded, ff/chrome will automatically end the unfinished ajax request, whereas ie will not. Manual abort () is required ()
2. The jquery (My tested version 1.4.2) abort () method has a bug and needs to be fixed.
3. Because abort () also triggers the success callback of jquery ajax, special processing is required.

 

From JsLover
 
Related Article

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.