简体   繁体   English

如何在SharePoint 2010中使用HTTP处理程序发出jQuery AJAX请求?

[英]How to make jQuery AJAX request with a HTTP Handler in Sharepoint 2010?

I'm developing a SP 2010 Visual Web Part that needs to load some data via AJAX. 我正在开发一个SP 2010 Visual Web部件,该部件需要通过AJAX加载一些数据。

I found this very helpful article but I'm having some doubts about it. 我发现这篇文章很有帮助,但是对此有一些疑问。

I have the Visual Web Part project, inside I have the Visual Web Part and some other files. 我有Visual Web部件项目,在内部有Visual Web部件和一些其他文件。 The article says I need to create an .ashx file that will acts as an HTTP handler. 文章说,我需要创建一个充当HTTP处理程序的.ashx文件。 So that's what I did, I created a "MyHandler.ashx" in the root of the project and put the WebHandler directive. 这就是我所做的,我在项目的根目录中创建了一个“ MyHandler.ashx”,并放置了WebHandler指令。 But I'm not sure about the Assembly directive. 但是我不确定Assembly指令。

Then it says we need to create an implementation to the handler and point it to it. 然后它说我们需要为处理程序创建一个实现并将其指向它。 I believe I have that part ok. 我相信那部分还可以。

Then I need to make the actual client call via jQuery. 然后,我需要通过jQuery进行实际的客户端调用。 Here's the part I don't know how to do it because I don't know the url where the .ashx is being deployed (if it's even being deployed...). 这是我不知道如何执行此操作的部分,因为我不知道将.ashx部署到的URL(如果甚至正在部署...)。

I'm trying: 我正在努力:

$.get('/_layouts/SomeNamespace/MyHandler.ashx', ...)

But it's not working... again, don't know the handler's url... 但这不起作用...再次,不知道处理程序的URL ...

I'm pretty new at Sharepoint development, so please don't be harsh =) 我在Sharepoint开发方面还很新,所以请不要苛刻=)

Thanks! 谢谢!

Here are simplified versions of my handler's files. 这是我的处理程序文件的简化版本。

MyHandler.ashx MyHandler.ashx

<%@ WebHandler Language="C#" Class="SomeNamespace.MyHandler" CodeBehind="MyHandler.cs" %>

MyHandler.cs MyHandler.cs

namespace SomeNamespace
{
    public class MyHandler : IHttpHandler
    {
        public bool IsReusable { get { return false; } }


        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("From the handler at " + DateTime.Now);
        }

        // bunch of methods
     }
}

I created a "MyHandler.ashx" in the root of the project 我在项目的根目录中创建了一个“ MyHandler.ashx”

You have to deploy MyHandler.ashx to _layouts/SomeNamespace/ folder. 您必须将MyHandler.ashx部署到_layouts / SomeNamespace /文件夹中。 Use Add -> SharePoint "_Layouts" Mapped Folder in Visual Studio Solution Explorer. 在Visual Studio解决方案资源管理器中,使用添加 -> SharePoint“ _Layouts”映射文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM