标题:ajax 在 firefox 下失效,不知道什么原因 附代码
取消只看楼主
amyeeq
Rank: 2
等 级:论坛游民
威 望:1
帖 子:63
专家分:10
注 册:2006-8-22
结帖率:66.67%
 问题点数:0 回复次数:0 
ajax 在 firefox 下失效,不知道什么原因 附代码
==========================================================================================================
function createXMLHttpRequest(){
    if(window.XMLHttpRequest){
        return new XMLHttpRequest();
    }else if(window.ActiveXObject){
var versions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
        for(var i = 0; i < versions.length; i++){
            try{
                var ieXmlHttp = new ActiveXObject(versions[i]);
                return ieXmlHttp;
            }catch(Error){throw new Error("create XMLHttp faile!!!!");}
        }
    }
    throw new Error("create XMLHttp faile!");
}
==========================================================================================================

var XMLHttpReq = null;
function sendRequest(url) {
    XMLHttpReq  =  createXMLHttpRequest();
    XMLHttpReq.open("GET", url, true);
    XMLHttpReq.onreadystatechange = processResponse;
    XMLHttpReq.send(null);  
}
==========================================================================================================
function processResponse() {
    if (XMLHttpReq.readyState == 4) {
        if (XMLHttpReq.status == 200) {
            var res=XMLHttpReq.responseText;
            window.alert(res);               
        } else {
            window.alert("fail");
        }
    }
}
==========================================================================================================
function sendUrl()
{
    var usernameText =     document.getElementById("username").value;
    var passwordText =     document.getElementById("password").value;
    //window.alert(usernameText);
    sendRequest("login.do?uname="+usernameText+"&upass="+passwordText+"");
}
搜索更多相关主题的帖子: ajax 代码 firefox 失效 
2009-07-18 00:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-279733-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.078867 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved