开发者

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.

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. The article says I need to create an .ashx file that will acts as an HTTP handler. So that's what I did, I created a "MyHandler.ashx" in the root of the project and put the WebHandler directive. But I'm not sure about the Assembly directive.

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. Here's the part I don't kno开发者_如何学编程w how to do it because I don't know the url where the .ashx is being deployed (if it's even being deployed...).

I'm trying:

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

But it's not working... again, don't know the handler's url...

I'm pretty new at Sharepoint development, so please don't be harsh =)

Thanks!

Here are simplified versions of my handler's files.

MyHandler.ashx

<%@ WebHandler Language="C#" Class="SomeNamespace.MyHandler" CodeBehind="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

You have to deploy MyHandler.ashx to _layouts/SomeNamespace/ folder. Use Add -> SharePoint "_Layouts" Mapped Folder in Visual Studio Solution Explorer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜