注册 登录
编程论坛 jQuery论坛

FireFox不支持Ajax的问题

乃别亚 发布于 2010-07-30 10:49, 1821 次点击
创建XmlHttpRequest声明:
var req;
function ajaxFunction()
{
try
   {
  // Firefox, Opera 8.0+, Safari
    req=new XMLHttpRequest();
   }
catch (e)
   {
 // Internet Explorer
  try
     {
      req=new ActiveXObject("Msxml2.XMLHTTP");
     }
  catch (e)
     {
     try
        {
         req=new ActiveXObject("Microsoft.XMLHTTP");
        }
     catch (e)
        {
        alert("您的浏览器不支持AJAX!");
        return false;
        }
     }
   }
}
function checkUserUid()
{
    var uid = document.getElementById("uid").value;
    var uidString = "uid=" + uid;
    uidString = uidString + "&method=checkUserUid";   
    var url = "../../HomePageAction.action";
         ajaxFunction();
         if (req) {
             req.open("POST", url, true);
             req.onreadystatechange = callbackUid;
             req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
             req.send(uidString);
         } else {
         document.write("xmlHttpReqest对象创建失败");        
         }
}

function callbackUid() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            var count = req.responseText;
            var chk_signup_uid = document.getElementById("chk_signup_uid");
            var infodisplay = "<font>用户名已经存在,请使用其他用户名</font>";
            var infodisplay1 = "<font>由英文字母、数字或下划线组成,并以英文字母开头。</font>";
            var infodisplay2 = "由英文字母、数字或下划线组成,并以英文字母开头。";
            if (count == 0) {               
                var uid = document.getElementById("uid").value;
                if (uid == "") {
                    document.getElementById("chk_signup_uid").innerHTML = infodisplay2;
                    return false;
                } else if (!/^\w+$/.test(uid)) {
                    document.getElementById("chk_signup_uid").innerHTML = infodisplay1;
                    return false;
                } else if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(uid)) {
                    document.getElementById("chk_signup_uid").innerHTML = infodisplay1;
                    return false;
                }
                   document.getElementById("chk_signup_uid").innerHTML = "成功";      
            } else if(count == 1){         
                   document.getElementById("chk_signup_uid").innerHTML = infodisplay;
            }         
        }      
    }
    else
    {
        document.getElementById("chk_signup_uid").innerHTML = "检测中...";
    }
 }
是不是我的JS有问题?FireFox支持JS,Ajax有什么要求呢?为什么IE支持而FireFox不支持,请大虾指点。

[ 本帖最后由 乃别亚 于 2010-8-3 13:15 编辑 ]
3 回复
#2
cnfarer2010-08-03 06:22
没有问题!
#3
2010-08-06 09:17
你可以通过firbug来检测一下。现在的frifox都应该自代了。
你按f12就可以看到。它们检查你的代码,和出错的原因

 
#4
beidoujs2011-05-24 07:38
楼上说的在理。
1