Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 2.47 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SharePoint Web Part : Can't make a jquery ajax call to ashx handler
  2. <div id="divProducts" style="height:300px;overflow:auto">
  3.     <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" EnableViewState="false">
  4.         <AlternatingRowStyle BackColor="White" />
  5.         <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
  6.         <HeaderStyle CssClass="header" BackColor="#990000" Font-Bold="True" ForeColor="White" />
  7.         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
  8.         <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
  9.     </asp:GridView>
  10. </div>
  11.  
  12. <div id="divProgress" style="margin-top: -50px;margin-left:150px;z-index:-999">
  13.     <asp:Image ID="image1" ImageUrl="~/_layouts/images/MyWebPart/loading.gif" width="100" height="100" runat="server" />
  14. </div>
  15.  
  16. <script type="text/javascript">
  17.     $(document).ready(function () {
  18.  
  19.         //initially hide the loading gif
  20.         $("#divProgress").hide();
  21.  
  22.         //Attach function to the scroll event of the div
  23.         $("#divProducts").scroll(function () {
  24.  
  25.             //User has scrolled to the end of the grid. Load new data..
  26.             $("#divProgress").ajaxStart(function () {
  27.                 $(this).show();
  28.             });
  29.             $("#divProgress").ajaxStop(function () {
  30.                 $(this).hide();
  31.             });
  32.  
  33.             BindNewData();
  34.  
  35.         });
  36.  
  37.     });
  38.  
  39.     function BindNewData() {
  40.             $.ajax({
  41.                 type: "GET",
  42.                 url: "/_layouts/MyWebPart/FetchRecordsHandler.ashx",
  43.                 success: function (data) {
  44.                     alert('data ', data);
  45.                 },
  46.                 error: function (xhr, ajaxOptions, thrownError) {
  47.                     alert(xhr.status);
  48.                     alert(thrownError);
  49.                 }  
  50.             });
  51.         }
  52. </script>
  53.        
  54. <%@ WebHandler Language="C#" Class="MyWebPart.Code.FetchRecordsHandler" CodeBehind="FetchRecordsHandler.cs" %>
  55.        
  56. namespace MyWebPart.Code
  57. {
  58.     class FetchRecordsHandler : IHttpHandler
  59.     {
  60.         public void ProcessRequest(HttpContext context)
  61.         {
  62.  
  63.             context.Response.Write("From the handler at " + DateTime.Now);
  64.  
  65.         }
  66.  
  67.         public bool IsReusable
  68.         {
  69.             get
  70.             {
  71.                 return false;
  72.             }
  73.         }
  74.     }
  75. }
  76.        
  77. <%@ WebHandler Language="C#" Class="MyWebPart.Code.FetchRecordsHandler, {my assembly}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" %>