简体   繁体   English

浏览器与AJAX功能的兼容性

[英]Browser compatibility with AJAX function

I have the following AJAX function that calls a PHP file to determine if an email is present in a db. 我有以下AJAX函数,该函数调用PHP文件以确定数据库中是否存在电子邮件。

<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. 我收到了用户的一些抱怨,但是我无法在IE,FF或Chrome浏览器中复制错误。

It won't work in Lynx, and it probably won't work in some specialized screen-reader browsers. 它在Lynx中不起作用,并且可能在某些专门的屏幕阅读器浏览器中不起作用。 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. 更好的是,使用类似jQuery的工具。 Realize that it's possible to fall back to an alternative approach of using a hidden <iframe> or something instead of XMLHTTPRequest. 意识到有可能退回到使用隐藏的<iframe>或其他代替XMLHTTPRequest的替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM