将.ASPX文件用作服务器端代码,由HTML / Javascript客户端通过AJAX调用 [英] Use .ASPX file as a Server-Side code to be called via AJAX by HTML/Javascript Client

查看:126
本文介绍了将.ASPX文件用作服务器端代码,由HTML / Javascript客户端通过AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中有数千名员工使用的工具。它们当前存储在文档库中的SharePoint 2010(很快将升级到2016)上。本质上,我们将SP2010用作Web服务器,因此我们不必为自己的Web服务器向业务部门收取巨额费用。

There are tools that are used by several thousand employees at my job. They are currently stored on SharePoint 2010 (to be upgraded to 2016 very soon) in a document library. Essentially, we're using SP2010 as a web server so we didn't have to charge a huge expense to our business unit for our own web server.

这些工具是全部基于HTML和JavaScript。但是,我正在尝试自动化用户当前正在手动输入的数据点的收集。为此,我发现最好的方法是查询始终为服务器端代码的LDAP,因为无法通过浏览器查询LDAP。在下面,您将看到我拥有的JavaScript和我拥有的ASPX文件(减去sharepoint自动创建的标头)。我正在将AJAX呼叫发送到ASPX文件,其中包含URL中的一些数据,这些数据是从LDAP获取剩余数据所必需的。但是,我回来的似乎是浏览器存储的所有代码,而不是我想要的一个JSON变量。

These tools are all based in HTML and JavaScript. However, I'm trying to automate the collection of data points that the user is currently inputting manually. To do this, I found that the best way would be to query the LDAP which is always going to be Server-Side code since there is no way to query the LDAP via the browser. Below, you'll see the JavaScript that I have and the ASPX file that I have (minus the header that sharepoint automatically creates). I'm sending an AJAX call over to the ASPX file with some data in the URL that will be needed to get the remaining data from the LDAP. However, what I'm getting back seems to be literally ALL of the code that is being stored by the browser versus the ONE JSON variable that I want.

首先是JavaScript :

First the JavaScript:

var ldapUserName;
var employee = {};
var ADSystem = new ActiveXObject("ADSystemInfo");
ldapUserName = ADSystem.UserName;

$.ajax({
    type: "GET",
    url: "http://my.url.where/i/am/storing/getEmp.aspx?username=" + ldapUserName,
    success: function(data) {
                employee = data;
                alert(employee);
             },
    error: function() {
            alert("Connection Failed");
           }
    });






接下来是ASPX文件(减去SharePoint标头)


Next, the ASPX file (minus the SharePoint header that's automatically added)

<% 
Option Explicit
Response.LCID = 1043
%>
<!--#include file="jsonObject.class.aspx" -->
<%
Dim username 
username = Request.QueryString("username")
empDemo(username)
Public Function empDemo(username)

'Create the Array that will be passed
Set JSON = New JSONobject

'Employee specific information
Set objUser = GetObject("LDAP://" & username)

JSON.Add "empNum", objUser.sAMAccountName
JSON.Add "fName", objUser.givenName
JSON.Add "lName", objUser.sn
JSON.Add "fullName", objUser.displayName
JSON.Add "ext", objUser.telephoneNumber
JSON.Add "title", objUser.title

JSON.Write()

End Function
%>

请注意,我正在提取一个文件,该文件可帮助VBScript处理JSON变量。该文件可以在此处找到

Notice that I'm pulling in a file which helps the VBScript work with JSON variables. That file can be found here.

同样,返回的字面意义实际上是ASPX文件的所有源代码。我需要的只是返回JSON变量。有人有任何建议吗?

Again, what getting back seems to be quite literally all of the source code of the ASPX file. What I need is to only get back the JSON variable. Anyone have any suggestions?

推荐答案

您的服务器不知道什么是 aspx文件。它认为这是一个文本文件,因此它只是返回文件的文本。

Your server does not know what an "aspx" file is. It thinks it is a text file and so its just returning the text of your file.

由于我不熟悉Sharepoint,因此不确定如何解决此问题。由于Sharepoint是一个文档管理系统,因此Sharepoint似乎正在为它创建内容。存储文档,然后允许人们下载它们。在Sharepoint服务器上似乎没有用于 aspx文件的解释器。

I am not sure how you would fix this as I am not familiar with Sharepoint. As Sharepoint is a document management system, It appears sharepoint is doing what it was built for. Storing documents and then allowing people to download them. There appears to be no interpreter on the Sharepoint servers for "aspx" files.

如果可能,此URL可能会提供帮助以启用此功能: https://support.microsoft.com/zh-cn /help/828810/how-to-enable-an-asp.net-application-on-sharepoint-virtual-server上运行

This URL might provide help in enabling this if it is even possible: https://support.microsoft.com/en-us/help/828810/how-to-enable-an-asp.net-application-to-run-on-a-sharepoint-virtual-server

这篇关于将.ASPX文件用作服务器端代码,由HTML / Javascript客户端通过AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆