weixin_33724059 2011-06-17 07:51 采纳率: 0%
浏览 28

使用jQuery Ajax刷新页面

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 &gt; 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 = &quot;&quot;;
       if (comments.LoadByPrimaryKey(Convert.ToInt32(id)))
           time = MyClass.GetTime(comments.CommentsDate);
       if (!(time.ToLower().Contains(&quot;sec&quot;) || time.ToLower().Contains(&quot;min&quot;)))
           time = &quot;&quot;;
       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.

  • 写回答

3条回答 默认 最新

  • weixin_33726943 2011-06-17 08:00
    关注

    When you use the jquery ajax function with the

    async: false,
    

    the page will remain busied until the request ends.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决