我尝试在向下滚动到底部时将新项目加载到电子商务网站。我做了它的大部分,但它获得相同的数据加载......我传递一个计数器(通过会话)来选择新的行,但它不起作用。asp.net jquery向下滚动时动态加载数据
这里是jQuery代码...
function sendData() {
<% Session["count_of_rows_displayed"] = Convert.ToInt16(Session["count_of_rows_displayed"].ToString()) + 1; %>
alert('<%= Session["count_of_rows_displayed"].ToString() %>');
$.ajax(
{
type: "POST",
url: "insaat.aspx/GetData",
data: "{'number_of_rows':'" + <%= Session["count_of_rows_displayed"].ToString() %> +"'}",
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");
}
});
}
这里是将WebMethod
[WebMethod]
public static string GetData(String number_of_rows)
{
int no = Convert.ToInt16(number_of_rows);
string resp = string.Empty;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
connection.Open();
adapter.SelectCommand = new SqlCommand("SELECT TOP " + (no*6) + " * FROM (SELECT TOP " + ((++no) * 6) + " * FROM Product ORDER BY id ASC) t ORDER BY id DESC", connection);
adapter.Fill(ds);
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1 && i < 24; i++)
// build the data
connection.Close();
return resp;
}
我试图增加会话,并与jQuery传递。但它不增加会话。我怎样才能让会话增加?
这或许可以帮助你... http://www.aspsnippets.com/Articles/Load-data-while-Scrolling-Page-down-with-jQuery-AJAX-and- ASPNet.aspx – Arbaaz 2013-03-06 19:11:18