2012-01-25 36 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

相關問題