我写的部分脚本涉及Google风格的智能搜索。页眉包含以下Javascript:
function showCustomer(str)
{
// remove white space from the name entered on the search screen
str = str.replace(" ", "");
var xmlhttp;
if (str=="")
{
document.getElementById("txtHint").innerHTML="No records found";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_customer.asp?q="+str,true);
xmlhttp.send();
}
元素txthint是一个空div,在textbox元素上,我有一个onkeyup。当我们使用Microsoft Access数据库时,这很有效,但现在,当我使用Active Directory时,似乎需要一段时间 - 首先返回整个列表,然后过滤结果。此文件中的代码如下所示:
<%@LANGUAGE="VBScript"%>
<!-- #include file="pagelets/includes/results.asp"-->
<%
response.Buffer = True
response.expires=-1
dim name, ADUser, objCom, objCon, objRS, membership, CentralUser, GroupMember
name = request.querystring("q")
ADUser = "LDAP://OU=Staff,OU=Users,DC=example,DC=internal"
' ADUser holds the LDAP query string
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\testuser"
objCon.Properties("Password") = "password"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
' objCon is the Active Directory object
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
' This sets the objCom to use the objCon object. The following query can then run and pull information back
objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl, memberOf FROM '" & ADUser & "' where givenName='*" & name & "*' OR sn='*" & name & "*' OR description='*" & name & "*' OR cn='*" & name & "*'AND UserAccountControl <> 514 ORDER BY cn ASC"
'This query selects information from Active Directory where the firstname, lastname or description is similar to the string which the user typed in. 512 is the User Account Control value for a normal account and 2 is the UserAccountControl value for a disabled account so we add these together to get 514. This is a normal user account that has been disabled.
Set objRS = objCom.Execute
'This will execute the above object
Response.Write "<table>" + vbCrLf
Do While Not objRS.EOF Or objRS.BOF
'This loops through the resultsset
Response.Write " <tr>"
Response.Write "<td>" + objRS("givenName") + "</td>"
Response.Write "<td>" + objRS("sn") + "</td>"
Response.Write "<td>" + objRS("mail") + "</td>"
' Check if field is null to avoid error
If IsNull(objRS.Fields("Description").Value) Then
sDesc = ""
else
For Each item In objRS.Fields("description").Value
sDesc = item + "<br>"
Next
end if
Response.Write "<td>" + sDesc + "</td>"
Response.Write "<td>" + objRS("mobile") + "</td>"
CentralUser = mid(Request.ServerVariables("AUTH_USER"), 11)
'This takes what the user is logged in as and, since, it will have the domain name in front of it, it will strip the RUGBY_B_C\ off
GroupMember = GroupCheck(CentralUser)
'This passes CentralUser to the GroupCheck function
Response.Write "<td>" + objRS("telephonenumber") + "</td>"
if objRS("sAMAccountName") = CentralUser then
'If the account name held in AD is different to the one the user is logged in with, a blank cell is output. If they are the same, a link allowing the user to edit their entry is displayed
Response.Write "<td><a href='entry.asp?account_name=" + objRS("sAMAccountName") + "'>Edit</a></td>"
'This will make a link using the sAMAccountName
elseif GroupMember = 1 then
'These are the accounts that are members of the "Team Carol" group
Response.Write "<td><a href='entry.asp?account_name=" + objRS("sAMAccountName") + "'>Edit</a></td>"
'This will make a link using the sAMAccountName
else
Response.Write "<td></td>"
'If neither condition is true, a blank cell is output
end if
Response.Write "</tr>" + vbCrL
objRS.MoveNext
Response.Flush
Loop
Response.Write "</table>"
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
我绝对没有iddea为什么它从数据库中提取时会立即起作用,但是当它从AD中拉出时需要时间