I have a web application where I am showing user comments on a page with its posting time. Since there are comments posted regularly so I need to update the comment posting time after every 1 minute. For this purpose I am using jquery ajax to update the time from db. My code is this:
<script type="text/javascript">
setInterval("UpdateTime()", 60000);
function UpdateTime() {
var id=$('#hdID').val();
$.ajax({
type: "POST",
url: "mypage.aspx/UpdateTime",
data: "{'id':'" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.d.length > 0) {
obj = document.getElementById('feed_TimeStamp' + id);
obj.innerHTML = msg.d;
//$(obj).slideDown("slow");
}
},
async: false,
error: function(xhr, status, error) {
//alert(xhr.statusText);
}
});
}
</script>
cs file:
[WebMethod]
public static string UpdateTime(string id)
{
Comments comments = new Comments();
string time = "";
if (comments.LoadByPrimaryKey(Convert.ToInt32(id)))
time = MyClass.GetTime(comments.CommentsDate);
if (!(time.ToLower().Contains("sec") || time.ToLower().Contains("min")))
time = "";
return time;
}
But here my issue is after every 1 minute when this web Method is executed the whole webpage is hanged away until the ajax call is finished. I want to refresh the time without busing the page.