Results 1 to 5 of 5
Threaded View
-
12-18-2006, 04:08 PM #1Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
How can i optimize the JS Ajax Code?
Code:var xmlHttp /* Process Username */ function processUsername(str) { if (str.length==0) { document.getElementById("usernameStatus").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajax_server/processUsername.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=usernameStateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function usernameStateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("usernameStatus").innerHTML=xmlHttp.responseText; } } /* Process Password */ function processPassword(str) { if (str.length==0) { document.getElementById("passwordStatus").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajax_server/processPassword.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=passwordStateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function passwordStateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("passwordStatus").innerHTML=xmlHttp.responseText; } } /* Process Gender */ function processGender(str) { if (str.length==0) { document.getElementById("genderStatus").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajax_server/processGender.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=genderStateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function genderStateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("genderStatus").innerHTML=xmlHttp.responseText; } } /* Process Email */ function processEmail(str) { if (str.length==0) { document.getElementById("emailStatus").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajax_server/processEmail.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=emailStateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function emailStateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("emailStatus").innerHTML=xmlHttp.responseText; } } /* Refresh Server Status */ function refreshServerStatus(str) { if (str.length==0) { document.getElementById("serverStatus").innerHTML=""; return; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="ajax_server/refreshServerStatus.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=serverStatusStateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function serverStatusStateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("serverStatus").innerHTML=xmlHttp.responseText; } } /* General Ajax Function */ function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp; }
:: www.AsuraHosting.com ::