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)?
You don't need Modernizer to test this, jQuery has it built-in.
if (jQuery.support.ajax) {
alert("Ajax is supported!");
}
Although i'm not sure exactly how jQuery handles $.ajax
calls when it isn't supported. It will either fail silently, or trigger the error callback. If it's important to you, you should test it.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With