Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

HTML
<div id="load_tweets">
</div>


This is the setinterval method inside ready function

JavaScript
setInterval(function () {
  $('#load_tweets').load("CS.aspx/fetch").fadeIn("slow");
  },1000);


And This is fetch [webMethod]

C#
[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

C#
[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);
});
Posted
Comments
Anil Sharma1983 16-Apr-16 2:20am    
setInterval(function () {
$('#load_tweets').load("CS.aspx/fetch").fadeIn("slow");
},1000);

Please check time interval is too fast

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900