我使用jquery在c#中使用Asp.net中的Infinite Scroll。当我运行这个程序时,它没有显示输出。
//这是我的index.html页面
<script type="text/javascript">
var j = 2;
function ram() {
abc(j);
j++;
}
j = j;
function abc(k) {//this function uses ajax to communicate with server
$.ajax({
type: 'post',
contentType: "application/json; charset=utf-8",
url: 'scroll.aspx/increasediv',
//here insertmethod is a function on page name datainsertusingjquery.aspx
data: "{'id':'" + k + "'}",//passing value of j in k and this k to function increasediv in code behind of scroll.aspx
async: false,
success: function (response) {
document.getElementById('para').innerHTML = response.d;
},
error: function (response) {
}
});
}
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
ram();
}
});
</script>
//这是我的.aspx页面
[WebMethod]
public static string increasediv(string id)
{
string s;
StringBuilder sb = new StringBuilder();
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\TestProjects\TeamB\3tire\scroll_may2\scroll_may2\App_Data\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand("select Youtube from Movie where ID<" + id, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
sb.Append("<iframe src='" + dr[0].ToString() + "' alt='DotNet Team' height='300px' width='400px'></iframe><br/>");
}
s = sb.ToString();
return s;
}
你能告诉我错过了什么吗?
答案 0 :(得分:0)
如果您没有填充初始值,则可能需要使用例如
$(window).ready(function(){
ram();
});
请参阅demo
其他一些事情