tags:

views:

34

answers:

3

I have the following AJAX function that calls a PHP file to determine if an email is present in a db.

<script language="javascript" type="text/javascript">
//Browser Support Code
function ajaxFunction(Email){

    var url="index.php?EmailCheck=Yes&Email=" + Email;

var ajaxRequest;  // The variable that makes Ajax possible!

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            alert("Your browser broke!");
            return false;
        }
    }
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        if(ajaxRequest.responseText == 0) {
                    alert("Sorry that email is not registered.");
                    } else {
                    alert("Login successful.");
                    window.opener.location.reload();
                    window.close();
                    }
    }
}

ajaxRequest.open("GET", url, true);
ajaxRequest.send(null); 

}

Are there going to be any browsers this won't work for? I have had some complaints from users, but I can't replicate the errors in IE, FF, or Chrome.

A: 

You may want to check out XMLHttpRequest.js, a standard-compliant cross-browser XMLHttpRequest object implementation. You can see the source code from the Google Code Browser.

Daniel Vassallo
A: 

Make sure you run a server side validation too.

Pentium10
A: 

It won't work in Lynx, and it probably won't work in some specialized screen-reader browsers. If you seriously expect to have users for which it won't work, for God's sake fix the error message. Better yet, use something like jQuery. Realize that it's possible to fall back to an alternative approach of using a hidden <iframe> or something instead of XMLHTTPRequest.

Pointy
Hey thanks for the down vote! After all, I had the nerve to answer the original question, which was "Are there any browsers this won't work for?"
Pointy