简体   繁体   English

如何正确地自动加载页面或A div?

[英]How can I properly load A page or A div automatically?

I'm creating A simple queuing system, right now when ever I click my button called BtnNxt() it will dequeue my enqueued data and render it to my page. 我正在创建一个简单的排队系统,现在当我单击名为BtnNxt()按钮时,它将使我排队的数据出队并呈现到我的页面。 and it also render from another page. 并从另一个页面进行渲染。 which is my call screen page, but when I click it again my call screen page needs to be refresh to update the current number from my queue. 这是我的呼叫屏幕页面,但是当我再次单击它时,需要刷新我的呼叫屏幕页面以更新队列中的当前号码。 so what I want is , Ithink i need to refresh my page or maybe my div to update it? 所以我想要的是,我想需要刷新页面或div来更新它吗?

Here is my BtnNext() controller : 这是我的BtnNext()控制器:

   public ActionResult BtnNext()
    {
        System.Threading.Thread.Sleep(500);
        var first = MyQueue.todayQueue.Dequeue();
        MyQueue.todayQueue.Count();
        TempData["QueueItem"] = first;
        TempData.Keep();
        return PartialView("_queuenumber");
    }

and here is my callscreen page: 这是我的呼叫屏幕页面:

@{
    var item = (Rosh.QueueMe.Web.Models.MyQueue)TempData["QueueItem"];
}
<table>
    <tr>
        <th scope="tickets">TICKETS</th>
        <th scope="name">NAME</th>
        <th scope="counter">COUNTER</th>
        <th scope="service">SERVICE</th>
    </tr>
    <tr class="data">
        <td>#@item.QueueNumber</td>
        <td>@item.Name</td>
        <td>Desk 1</td>
        <td>@item.ServiceId</td>
    </tr>
</table>

I tried to use this code 我尝试使用此代码

<meta http-equiv="refresh" content="1" />

this code refresh my page every 1 sec, but is it possible to just reload the div? 此代码每1秒刷新一次我的页面,但是是否可以重新加载div? maybe using ajax? 也许使用ajax?

use asyn keyword both side server & client, add the spinner loaders to each and every div which you want to make automatically load. 在服务器和客户端同时使用asyn关键字,将微调加载器添加到要自动加载的每个div中。 don't make any custom tread because sometime thread take more time but actually he didn't need more time for sleep, so best solution is make every controller ayns and caller must be asyn as well. 不要进行任何自定义操作,因为有时线程会花费更多时间,但实际上他不需要更多时间睡觉,因此最好的解决方案是使每个控制器ayns和调用者也必须异步。

<script type="text/javascript">
    $(function() {
        setInterval(loadData,1000);  // invoke load every second
        loadData(); // load on initial page loaded
    });

    function loadData() {
        $('#Div').load( '/controller/BtnNext' );
    }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM