weixin_33709590 2017-03-20 20:29 采纳率: 0%
浏览 19

在AJAX上丢失到.ASP文件

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?

  • 写回答

1条回答 默认 最新

  • 三生石@ 2017-03-20 20:56
    关注

    Instead of "return Employee", have you tried:

    response.write employee
    

    or maybe

    response.write employee.sAMAccountName
    

    Is this VB6? Not sure what libraries are available in classic asp, so you might have to manually write the data in JSON form... i.e...

    response.write "{ name: " & employee.sAMAccountName & "}"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵