#2
cnfarer2010-08-03 06:22
|
创建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 编辑 ]