前端之家收集整理的这篇文章主要介绍了
Ajax小应用函数,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
function Ajax(data)
{
createXMLHttpRequest();
if(data==document.getElementById("username"))
{
xmlhttp.open("GET","user_ck.PHP?username="+data.value,true);
document.getElementById('username_notice').innerHTML = process_request;//显示状态
}
else if(data==document.getElementById("veruserid"))
{
xmlhttp.open("GET","user_ck.PHP?veruserid="+data.value,true);
document.getElementById("veruserid_notice").innerHTML = process_request;//显示状态
}
else if (data==document.getElementById("verify"))
{
xmlhttp.open("POST","veruser_check.PHP",true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
document.getElementById("verify_notice").innerHTML = process_request;//显示状态
}//"checkcode="+checkcode.value+"&username="+
xmlhttp.onreadystatechange=function()
{ //alert("zhong");
if (4==xmlhttp.readyState)
{
if (200==xmlhttp.status)
{
var responseText = xmlhttp.responseText;
responseText= responseText.replace(/(^\s*)|(\s*$)/g,"");
if (responseText=="true" )
{
ck_user(data,"true");
}
else
{
ck_user(data,"false");
}
}
else
{
alert("发生错误!");
}
}
}
if(data==document.getElementById("veruserid")||data==document.getElementById("username"))
{
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}
else if (data==document.getElementById("verify"))
{
xmlhttp.send("veruserid="+document.getElementById("veruserid").value+"&veruserpwd="+document.getElementById("verpassword").value);
}
}
原文链接:https://www.f2er.com/ajax/166304.html