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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀