Search code examples
ajaxjquerymodernizrprogressive-enhancement

How can I use Modernizr to test a browser for AJAX support?


As a big fan of Progressive-Enhancement, I use Modernizr to test browser capabilities. How can I use Modernizr to test the browser's support of AJAX (specifically, jQuery's AJAX functions)?


Solution

  • For what it's worth, I have added issue #734 to Modernizr to add a test for AJAX, developed the test, created a JSFiddle to test, er, the test...and initiated a pull-request (issue #735) back to the fine folks who maintain Modernizr.

    The relevant JS:

    Modernizr.addTest('ajax', function() {
        var xhr = new XMLHttpRequest();
        return !!('onreadystatechange' in xhr);
    });