ykuramochi / jquery-jsonp

Automatically exported from code.google.com/p/jquery-jsonp
0 stars 0 forks source link

Firefox displays page loading indicator while JSONP requests are running. #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using JSONP for long-polling, i.e. it can take a minute until a request 
returns, and then 
immediately a new one is sent. In Firefox, the page loading indicator 
("throbber") is spinning forever 
in this case.

In order to prevent this, I propose to create the iframe element in the onload 
handler of the iframe, 
causing Firefox to avoid displaying the throbber:

            // Write to the document
            document.write([
                '<html><body onload="(function() {',
                'var s = document.createElement(\'script\'); s.type = \'text/javascript\'; s.src=\'', finalUrl, '\'; 
document.body.appendChild(s);',
                '})();"></body></html>'
            ].join(empty)
            );

Would be great if this could be implemented in the library. Error callbacks 
such as onreadystate are 
not currently incorporated in my "patch", but I think you have more experience 
on which ones are 
appropriate. (Does not being able to use <body onload> for the error callback 
cause issues?)

Original issue reported on code.google.com by thomas...@gmail.com on 30 Apr 2010 at 12:11

GoogleCodeExporter commented 8 years ago
"Does not being able to use <body onload> for the error callback cause issues?"

This. The only reason to use an iframe in the first place was to have a 
cross-browser 
way to detect errors using the iframe lifecycle itself. I'm currently working 
on 
other means to detect errors for other browsers, but that's still a work in 
progress 
(though I may have a solution for IE now).

I'm putting this on hold, for the sole reason it means a new way of detecting 
jsonp 
errors in FF.

Original comment by aubourg.julian on 2 May 2010 at 1:06

GoogleCodeExporter commented 8 years ago
I found you can use onerror in Firefox. The following is working for me:

            // Write to the document
            if ($.browser.mozilla)
                document.write([
                    '<html><body onerror="',errorCallbackName,'()" onload="(function() {',
                        'var s = document.createElement(\'script\');',
                        's.type = \'text/javascript\';',
                        's.src=\'', finalUrl, '\';',
                        's.onload=', errorCallbackName, ';',
                        'document.body.appendChild(s);',
                    '})();"></body></html>'
                ].join(empty)
                );
            else
                document.write([
                    '<html><head><script src="',
                    finalUrl,'" onload="',
                    errorCallbackName,'()" onreadystatechange="',
                    errorCallbackName,'(this.readyState)"></script></head><body onload="',
                    errorCallbackName,'()"></body></html>'
                ].join(empty)
                );

Original comment by thomas...@gmail.com on 2 May 2010 at 3:36

GoogleCodeExporter commented 8 years ago
The only caveat that remains is that the page loading indicator is still 
spinning for a very short time in Firefox 
and in Chrome as well (when creating an iframe or calling document.open() on 
it). Haven't found a way to prevent 
this :-( I am thinking of creating multiple iframes at the beginning and then 
reusing them in order to allow 
multiple concurrent JSONP requests and preventing the page load indicator to 
show up.

Original comment by thomas...@gmail.com on 2 May 2010 at 3:40

GoogleCodeExporter commented 8 years ago
2.0pre uses a similar trick as the one you suggested. This is as fixed as it 
can get 
for now I'm afraid.

Original comment by aubourg.julian on 11 May 2010 at 5:13

GoogleCodeExporter commented 8 years ago
2.0pre2 should completely remove the problem in FF. Webkit browsers (Chrome, 
Safari) 
are still using iframes though.

Original comment by aubourg.julian on 12 May 2010 at 12:35

GoogleCodeExporter commented 8 years ago
Also, this was a duplicate of #7

Original comment by aubourg.julian on 27 May 2010 at 10:48