52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
function checkUser(str) // Creates a new checkUser function.
|
|
{
|
|
|
|
if (str.length==0) // checks if the str variable inside the checkUser function is equal to 0
|
|
{
|
|
document.getElementById("validateCheck").innerHTML=""; // Gets the html object by it's id, in this case it's id is validateCheck
|
|
return; // Returns the end result of the function
|
|
}
|
|
|
|
xmlHttp=GetXmlHttpObject();
|
|
if (xmlHttp==null) // Checks whether the users browser allows ajax
|
|
{
|
|
alert ("Please use a browser that has ajax enabled!"); // Alerts if the users browser does not support ajax
|
|
return; // Returns the function
|
|
}
|
|
|
|
var url="validation/usercheck.php"; // Creates a new variable called url
|
|
url=url+"?search="+str; // Assigns an id to the php file (usercheck.php?id=user)
|
|
url=url+"&sid="+Math.random(); // Assigns a random math function to the url
|
|
xmlHttp.onreadystatechange=stateChanged; // If the forms state has changed
|
|
xmlHttp.open("GET",url,true); // Gets a pages content using ajax
|
|
xmlHttp.send(null);
|
|
}
|
|
|
|
function stateChanged()
|
|
{
|
|
if (xmlHttp.readyState==4)
|
|
{
|
|
document.getElementById("validateCheck").innerHTML=xmlHttp.responseText;
|
|
}
|
|
}
|
|
|
|
function GetXmlHttpObject()
|
|
{
|
|
var xmlHttp=null;
|
|
try
|
|
{
|
|
xmlHttp=new XMLHttpRequest();
|
|
}
|
|
catch (e)
|
|
{
|
|
try
|
|
{
|
|
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
|
|
}
|
|
catch (e)
|
|
{
|
|
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
|
|
}
|
|
}
|
|
return xmlHttp;
|
|
} |