gpt4 book ai didi

c# - 无尽的滚动asp.net

转载 作者:行者123 更新时间:2023-11-30 12:56:56 25 4
gpt4 key购买 nike

abc我尝试使用 WebMethod 创建无限滚动,但我总是收到“失败”消息。我检查了我的代码,没有发现任何错误。这是我的代码:

代码隐藏:

public int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to showing 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>

这是我的脚本端:

 <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>

为什么会失败?滚动时我总是收到警报(“失败”)。请帮忙!感谢您的回答

最佳答案

试试这个方法,简单快捷

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

$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
sendData();
}
});

function sendData() {
$.ajax(
{
type: "POST",
url: "AjaxProcess.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",

success: function (msg) {
$("#myDiv").append(msg.d);
},

Error: function (x, e) {
alert("Some error");
}

});

}

});


</script>
</head>
<body>
<form id="form1" runat="server">
<div id="myDiv">
</div>
</form>
</body>



[WebMethod]
public static string GetData()
{
string resp = string.Empty;
resp += "<p><span></span> This content is dynamically appended to the existing content on scrolling.</p>";
return resp;
}

关于c# - 无尽的滚动asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18759898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com