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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建