I'm gonna load tweet from database but it doesn't work please check where i'm doing mistake
Quote:
This is the div where i want to load tweets
<div id="load_tweets">
</div>
This is the setinterval method inside ready function
setInterval(function () {
$('#load_tweets').load("CS.aspx/fetch").fadeIn("slow");
},1000);
And This is fetch [webMethod]
[System.Web.Services.WebMethod]
public static DataTable fetch()
{
SqlConnection con = new SqlConnection("data source=dbcomments;initial catalog=CommentSystemUsingAjax;integrated security=true");
SqlDataAdapter da = new SqlDataAdapter("select * from tbl_tweet order by tweet_id desc", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
And i also tried this way
[System.Web.Services.WebMethod]
public static string fetch(string tweet)
{
SqlConnection con = new SqlConnection("data source=dbcomments;initial catalog=CommentSystemUsingAjax;integrated security=true");
SqlDataAdapter da = new SqlDataAdapter("select * from tbl_tweet order by tweet_id desc", con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
tweet = dt.Rows[0]["tweet"].ToString();
}
return tweet;
}
Please help me
What I have tried:
<script type="text/javascript">
$(document).ready(function () {
$('#btn_tweet').click(function () {
$.ajax({
type: "POST",
url: "CS.aspx/Hello",
data: '{tweet: "' + $("#<%=tweet.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#tweet').val("");
alert("ok");
}
});
setInterval(function () {
$('#load_tweets').load("/CS.aspx.aspx/fetch").fadeIn("slow");
}, 1000);
});