Detect AJAX support for non-AJAX browsers...?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Detect AJAX support for non-AJAX browsers...?

Post by JAB Creations »

Yes I understand that except for some guy on a 14K modem connected to his Commodore 64 computer living on some far off north Canadian island may be the only person alive using Netscape 6 or Opera 8.01, however I still would like to figure out how to correctly test for AJAX support in such browsers. I am currently using Opera 7.54 (my site roughly supports 4.0+ as well as IE4). I'm not spending much time in these older browsers but I find the challenge fun. :mrgreen:

So there are multiple objects to test for but the tests I've tried don't seem to work in Opera 7.54...

Code: Select all

if (XMLHttpRequest) {alert('yes');}else if (!XMLHttpRequest) {alert('no');}
I don't want to do anything too fancy, just an alert for either/or supported or not. Yes I know I'm :crazy: but this is not an April fools joke. :twisted:
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Re: Detect AJAX support for non-AJAX browsers...?

Post by WaldoMonster »

Maybe something like this:

Code: Select all

if (typeof XMLHttpRequest == 'undefined')
    alert('no');
else
    alert('yes');
This can give wrong information when an ActiveX XMLHttpRequest wrapper is used with another object as XMLHttpRequest.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Detect AJAX support for non-AJAX browsers...?

Post by JAB Creations »

This worked however since IE8 disabled all my standalones except IE7 I can't test this against older versions of IE (4,5,6)...

Code: Select all

if (window.XMLHttpRequest)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Detect AJAX support for non-AJAX browsers...?

Post by Jonah Bron »

This is what I usually use

Code: Select all

var ajax;
var ajaxSupported = true;
try {
    ajax = new XMLHttpRequest();
}catch (e){
    try {
        ajax = new ActiveXObject('Msxml2.XMLHTTP');
    }catch (e){
        try {
            ajax = new ActiveXObject('Microsoft.XMLHTTP');
        }catch (e){
            ajaxSupported = false;
        }
    }
}
Post Reply