Phil J
2008-Jan-17 15:10 UTC
Prototype asynch Ajax.Request timing out, synchronous works fine
While searching for solutions to my problem I''ve seen postings complaining of similar problems, but the issues raised all seemed to be caused by the user''s script in some way or another. My problem quite likely falls into the same category but after several days of searching I''ve failed to find the solution so I''m asking for help. Please be gentle with me if I''ve done something really daft! *Problem statement:* My Ajax call times out in the browser if it''s done asynchronously, but works a treat and completes almost immediately if it''s done synchronously. *Scenario:* I''m embedding flash objects dynamically on a page using SWFObject v 2.0 RC1. The flash object in question is the FlowPlayer flash player. The flash video is being streamed from lighttpd and modsecdownload is being used to prevent bandwidth theft. Ajax is being used to generate the encoded URL for modsecdownload. I''m doing the encoded URL generation server side as this means that I can use the server timestamp rather than risking using the client machine''s clock. Even more importantly it also means I don''t have to expose the server secret in the client script. Server side I''m using a small PHP module to take the flash video filename as a GET parameter and return the encoded URL. Server logs show that the request is being returned every time in a timely fashion - stand-alone tests show the response to be extremely quick, almost instantaneous. The server module sets all of the HTTP cache-control, expiry, last-modified etc headers that I can think of. This is my Ajax call: function getEncryptedFlvUrl (flvname) { var url = flvUrlMunger + flvname; ajaxSemaphore = ''Busy'' ; // Global variable new Ajax.Request(url, { method: ''get'', asynchronous: true, onSuccess: function(transport) { ajaxSemaphore = ''Idle''; ajaxResponse = transport.responseText; // Global variable return true; }, onFailure : function() {alert("Oops: Ajax problem");} }); } My script calls the above routine, performs some animations with Scriptaculous and then waits on the completion semaphore ajaxSemaphore. The intention is that the slight delay caused by the Ajax call will take place during the animations so that the user experience is uninterrupted. Using a synchronous call causes a slight but noticeable glitch. *Further observations* This problem has been tested with: Firefox 2.0.0.11 (Gentoo Linux, standard ebuild) Firefox 2.0.0.11 (Windows XP, standard binary) on two different and completely unrelated networks Internet Explorer 7.0 (Windows XP) on two different and completely unrelated networks The result is always the same. I''ve tried placing an Alert in the onSuccess routine as well as watching everything with Firebug. This confirms that my timer routine is working correctly, or at least is not causing the problem anyway. I''ve also tried extending the script timeout in Firefox. *Interestingly*, about 60 - 70% of the time the onSuccess routine seems to fire exactly as the script times out - regardless of how small or large the script timeout is. I''ve seen this happen reprodicibly with the standard 10 second timeout and also with a 60 second timeout, in Firefox at least. I''m using Prototype 1.6. Also loaded are Scriptaculous 1.8 and SWFObject 2.0 RC1, as well as my own script. http://tmcinternet.com/hb/demobox.html demonstrates my problem. My script (derived from Lokesh Dhakar''s excellent lightbox2) is still a work in progress in other respects too - the object embedding needs to happen later in the animation, for example. Anyway thanks for reading this far. I''ve dumped pretty much everything I can think of that might be of help in understanding what I''ve done. Help, please? Cheers Phil --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---