我嘗試在向下滾動到底部時將新項目加載到電子商務網站。我做了它的大部分,但它獲得相同的數據加載......我傳遞一個計數器(通過會話)來選擇新的行,但它不起作用。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