I attempted to implement an infinite scroll feature using a WebMethod, but I keep receiving a "failed" message. After reviewing my code, I couldn't identify any errors. Below is the code snippet:
Code Behind:
public int CurrentPage
{
get
{
// check for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to displaying the first page
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
sqlConn.ConnectionString = ConfigurationManager.AppSettings["Database"];
ItemsGet("EN");
}
[WebMethod]
public void ItemsGet(string Language)
{
try
{
sqlConn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(@" Database query...", sqlConn);
DataSet ds = new DataSet();
myCommand.Fill(ds);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 9;
objPds.CurrentPageIndex = CurrentPage;
Repeater1.DataSource = objPds;
Repeater1.DataBind();
}
catch (Exception ex)
{
}
}
ASPX:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<ul class='hover_block'>
<li style=''>
<a style='width: 524px;margin-top:-1px;margin-left:-1px; height: 365px;border:1px solid #cecece; background-color: #ECecec;' href=' <%#DataBinder.Eval(Container.DataItem,"RecID") %>'>
<img src='abc.com.tr/news/img/<%#DataBinder.Eval(Container.DataItem,"Image1")%>' alt='' class='left' style='margin-right: 10px; width: 500px; height: 300px;'/>
<div class='Icerik'>
<h3 class='News_Head'> <%#DataBinder.Eval(Container.DataItem,"Head") %></h3>
<p style='font-family:Tahoma;'> <%#DataBinder.Eval(Container.DataItem,"Content") %></p>
<b class='info'>View More</b>
</div>
</a>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
JavaScript Side:
<script type="text/javascript">
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
$.ajax({
type: "POST",
url: "default.aspx/ItemsGet",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded() {
alert("result.d");
}
function AjaxFailed() {
alert("Failed");
}
}
});</script>
What could be causing the failure? I consistently receive the alert("Failed") message while scrolling. Any assistance would be greatly appreciated. Thank you for your responses.