我在view页面动态绑定了一个table,我想用ajax每隔几秒钟重新绑定下这个table,如何去实现,本人刚接触mvc3,不是很懂,望各位兄弟帮忙,最好有代码示例,view的跟controller的,谢谢

解决方案 »

  1.   

    <table cellpadding="0" cellspacing="0" border="0" id="table_1" class="uiTable report"> 
    <thead> 
    <tr> 
    <th width="16px;"><h3></h3></th> 
    <th><h3>车站名称</h3></th> 
    <th><h3>工作状态</h3></th> 
    <th width="16px;"><h3></h3></th> 
    <th><h3>车站名称</h3></th> 
    <th><h3>工作状态</h3></th> 
    <th width="16px;"><h3></h3></th> 
    <th><h3>车站名称</h3></th> 
    <th><h3>工作状态</h3></th> 
    </tr> 
    </thead> 
    <tbody>    
                            @{ var row = 1;  }                
                            @foreach (var item in Model)
                            {
                                if(row == 1) {
                                    @:<tr>
                                }
                                if (item.Total > 0)
                                {
                                    <td><img src="@Url.Content("~/Content/img/alarm.png")" /></td>
                                    <td bgcolor="yellow">@item.STATION_NAME</td>
                                    <td bgcolor="yellow"><a href="[email protected]_ID&[email protected]_NAME">异常(@item.Total)</a></td>
                                }
                                else
                                {
                                    <td><img src="@Url.Content("~/Content/img/ok.png")" /></td>
                                    <td>@item.STATION_NAME</td>
                                    <td>正常</td>
                                }
                                if (row == 3)
                                {
                                @:</tr>
                                row = 1;
                                }
                                else
                                {
                                    row++;
                                }
                            }
                            @for (int i = row; i < 3; i++)
                            {
                                @:</tr>
                            }
    </tbody> 
    </table>
    相关的table是这样的
      

  2.   

    ajax定时(setInterval)请求了数据了,获取数据后,覆盖现有table数据
      

  3.   

    能不能给点代码示例,我主要问题在重新绑定数据上,不晓得如何重新绑定table
      

  4.   


    <script type="text/javascript">
    function LoadData() {
            $.ajax({
                url: "/Home/AjaxLoad",
                type: "get",           
                success: function (responseText, statusText) {
                    //此处处理数据逻辑,responseText可以是json数据,js处理拼接后加载覆盖table内容
                 
                }
            });
        }
        setInterval("LoadData();", 2000);//如2000表示2秒请求一次
    </script>