I have a need to automate data collection for users who visit specific pages of my site. To do this, I'm querying the LDAP. The LDAP query works just fine when I double click on the file locally (.vbs
). However, when I double click on it while it's on the server, it doesn't work (as would be expected). However, I'm as new as new can get to writing VBScript.
After reading a few articles I modified the code and changed the extension to .asp
. I ended up with this:
<%
On Error Resume Next
'Create the Array that will be passed
Dim employee(7)
'Employee System Related Info
Set objSysInfo = CreateObject("ADSystemInfo")
employee(0) = objSysInfo.SiteName
'Employee specific information
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
employee(1) = objUser.sAMAccountName
employee(2) = objUser.givenName
employee(3) = objUser.sn
employee(4) = objUser.displayName
employee(5) = objUser.telephoneNumber
employee(6) = objUser.title
Return employee
%>
In the JavaScript function which would call this .asp
file via ajax, I am able to get the employee number which I think could be received by the .asp
file and do the rest of the query.... However, I'm not even sure if I'm returning everything correctly in the VBScript
. Furthermore, I'm not even sure if I should be using a GET
or POST
AJAX call. Can someone point me in the right direction?
Updated 03/22/2017 at 10AM CDT
I've finally gotten back to the office and tried to play around. I'm still a little lost. I've made some updates to the code below you'll see the javascript and the VBScript
FIRST the JavaScript:
var employee = {};
function getEmp() {
var ldapUserName = ADSystem.UserName;
$.ajax({
type: "POST",
data: ldapUserName,
url: "https://here.is.my/url.asp",
success: $.ajax({
type: "GET",
dataType: "json",
success: function(responseText) {
employee = responseText;
},
error: function() {
alert("No Data Received");
}
}),
error: function() {
alert("Connection Failed");
}
});
}
Now here is the updated VBScript based on a few things I read and the suggestions from here:
<%
Public Function empDemo(username)
On Error Resume Next
'Create the Array that will be passed
Dim employee(7)
'Employee System Related Info
Set objSysInfo = CreateObject("ADSystemInfo")
employee(0) = objSysInfo.SiteName
'Employee specific information
strUser = objSysInfo.username
Set objUser = GetObject("LDAP://" & strUser)
employee(1) = objUser.sAMAccountName
employee(2) = objUser.givenName
employee(3) = objUser.sn
employee(4) = objUser.displayName
employee(5) = objUser.telephoneNumber
employee(6) = objUser.title
response.write "{ site: " & employee(0) & ","
& "empNum: " & employee(1) & ","
& "empFName: " & employee(2) & ","
& "empLName: " & employee(3) & ","
& "empFullName: " & employee(4) & ","
& "empExt: " & employee(5) & ","
& "empTitle: " & employee(6) & "}"
End Function
%>
Currently, I'm getting the alert stating "No Data Received". What am I doing wrong?