Hello, Does anyone have an elegant way to check if the client supports AJAX? I''m currently using: var _supportsAjax = (Ajax.getTransport()) ? true : false; Thanks, Ed C. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A little bit shorter, and does the same: var _supportsAjax = !!Ajax.getTransport(); I think there''s no better way to acomplish this. hth sigi On 9/13/06, Ed C. <defeated2k4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > Does anyone have an elegant way to check if the client supports AJAX? I''m > currently using: > > var _supportsAjax = (Ajax.getTransport()) ? true : false; > > Thanks, > Ed C. > > > >-- Siegfried Puchbauer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How about - detectAJAX = function() { try { xmlhttpcheck = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttpcheck = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttpcheck = new XMLHttpRequest(); } catch (e) { xmlhttpcheck = false; }}} if (!xmlhttpcheck) { return false; } else { return true; } }; Thanks, Mandy. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maninder, Singh a écrit :> How about - > > detectAJAX = function() { > try { xmlhttpcheck = new ActiveXObject("Msxml2.XMLHTTP"); } > catch (e) { try { xmlhttpcheck = new ActiveXObject("Microsoft.XMLHTTP"); } > catch (e) { try { xmlhttpcheck = new XMLHttpRequest(); } > catch (e) { xmlhttpcheck = false; }}} > if (!xmlhttpcheck) { > return false; > } > else { > return true; > } > };Is this intended as a joke, Mandy :-)? First: the final 6 lines should read "return xmlhttpcheck;" for the sake of conciseness w/o loss of readability. Second, this duplicates the code from Ajax.getTransport(). I mean, scary duplicates, because it doesn''t even use Try.These. Of course, maybe you''re going for no-Prototype-dependency, but isn''t this a Prototype/s.a.u. list? Therefore, the previous solution: !!Ajax.getTransport(), is way better, wouldn''t you say? Best, -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>>Is this intended as a joke, Mandy :-)?Not really, but from time to time, people find what I say funny! ;)>>First: the final 6 lines should read "return xmlhttpcheck;" for the sakeof conciseness w/o loss of readability. Not necessarily. This is just for checking support. You are not processing anything You don''t need to get a reference back to the object. You will show a non ajax version of the page to the user if no support is enabled and let the user in - to the ajax version if support is enabled, rather than letting him to an ajax version and somwhere in between discovering that there is no ajax support when you send an xmlhttp request.>>Second, this duplicates the code from Ajax.getTransport(). I mean,scary duplicates, because it doesn''t eve Sure, I did not see your solution. Yes, this is a non-prototypish way. But, hey - it''s just brainstorming here - right? And you can always add your prototyp''ish way to the above code (if you want). In the end it''s always about what suits you. Thanks, Mandy. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---