2012-01-25 35 views
0

我的Web部件中有一个可滚动的GridView,我必须在每个用户滚动条上进行AJAX调用。我使用Web部分中的Jquery 1.7.1来调用c#处理程序类。SharePoint Web部件:无法对ashx处理程序进行jquery ajax调用

我收到错误500:内部服务器错误。

这里是ASCX的一个样本:

<div id="divProducts" style="height:300px;overflow:auto"> 
    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" EnableViewState="false"> 
     <AlternatingRowStyle BackColor="White" /> 
     <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> 
     <HeaderStyle CssClass="header" BackColor="#990000" Font-Bold="True" ForeColor="White" /> 
     <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> 
     <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> 
    </asp:GridView> 
</div> 

<div id="divProgress" style="margin-top: -50px;margin-left:150px;z-index:-999"> 
    <asp:Image ID="image1" ImageUrl="~/_layouts/images/MyWebPart/loading.gif" width="100" height="100" runat="server" /> 
</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 

     //initially hide the loading gif 
     $("#divProgress").hide(); 

     //Attach function to the scroll event of the div 
     $("#divProducts").scroll(function() { 

      //User has scrolled to the end of the grid. Load new data.. 
      $("#divProgress").ajaxStart(function() { 
       $(this).show(); 
      }); 
      $("#divProgress").ajaxStop(function() { 
       $(this).hide(); 
      }); 

      BindNewData(); 

     }); 

    }); 

    function BindNewData() { 
      $.ajax({ 
       type: "GET", 
       url: "/_layouts/MyWebPart/FetchRecordsHandler.ashx", 
       success: function (data) { 
        alert('data ', data); 
       }, 
       error: function (xhr, ajaxOptions, thrownError) { 
        alert(xhr.status); 
        alert(thrownError); 
       } 
      }); 
     } 
</script> 

我补充说,将在我的Web部件项目(设计/ MyWebPart/FetchRecordsHandler.ashx)的布局文件夹中部署的ASHX文件:

<%@ WebHandler Language="C#" Class="MyWebPart.Code.FetchRecordsHandler" CodeBehind="FetchRecordsHandler.cs" %> 

我创建的类FetchRecordsHandler与正确的命名空间实现的IHttpHandler:

namespace MyWebPart.Code 
{ 
    class FetchRecordsHandler : IHttpHandler 
    { 
     public void ProcessRequest(HttpContext context) 
     { 

      context.Response.Write("From the handler at " + DateTime.Now); 

     } 

     public bool IsReusable 
     { 
      get 
      { 
       return false; 
      } 
     } 
    } 
} 

此方法在我的Web部件中不起作用。任何想法的解决方案或可能是另一种技术,使从滚动事件到Web部件的Ajax调用?

THX

回答

0

您需要将您的ashx的更改为类似:

<%@ WebHandler Language="C#" Class="MyWebPart.Code.FetchRecordsHandler, {my assembly}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" %> 

其中{我的组装}是编译的.dll的名称(不带.dll文件),可能MyWebPart和xxxxxxxxxxxxxxxx是组件的公钥标记。找到这种方法的一种方法是从Web部件中查看部署的.ascx,第一行或其他部分应该包含类似的东西。

我想你收到的500错误与SharePoint无法为你的.ashx加载程序集有关。您可以在事件查看器中查看更多详细信息。

+0

因为我没有太多时间来完成这项任务,所以我选择了另一种可行的解决方案(使用带有codeBehind的aspx)。我第一次有空,我正在测试你的解决方案。谢谢 – Dino

相关问题