简体   繁体   English

添加新数据时自动刷新另一个页面Laravel 5.8 Ajax

[英]Auto refresh an another page when new data is added Laravel 5.8 Ajax

I've been searching and trying on how to refresh an another page or blade file when a data is updated. 我一直在搜索并尝试在更新数据时如何刷新另一个页面或刀片文件。 In my case, whenever I click the Call Next button in my call.blade.php, the data would update or change in my wintwo.blade.php. 就我而言,每当我单击call.blade.php中的“ 呼叫下一个”按钮时,数据就会在wintwo.blade.php中更新或更改。

ui for call.blade.php ui的call.blade.php 叫ui

ui for wintwo.blade.php ui for wintwo.blade.php 窗口用户界面

Controller Store Code 控制器存储代码

$call = Call::find($request->id);
$call->user_id = Auth::user()->id;
$call->counter_id = Auth::user()->counter_id;
$call->called = 'YES';
$call->save();

return response()->json($call);

call.blade.php javascript code call.blade.php JavaScript代码

<script type="text/javascript">
$('#update').click(function(){
    $.ajax({
        type:'post',
        url: 'updatecall',
        data:{
            '_token':$('input[name=_token]').val(),
            'id':$('input[name=call_id]').val(),
        },
        success:function(data){
            window.location.reload(); 
            setInterval(function() {
                $('#update').load('{{ action('DetailController@index') }}');
            }, 1000);
        },
    });
}); </script>

wintwo.blade.php javascript code wintwo.blade.php javascript代码

<script type="text/javascript">
    $(document).ready(function () {
        window.setTimeout(function () {

            window.location.href = '/queue'; // "/queue" is the url route for wintwo.blade.php

        }, 2000);

    }
</script>

It doesn't work. 没用 I've search a lot and tried but nothing gonna work. 我已经搜索了很多,并尝试了但没有任何效果。

您必须使用Web套接字服务,例如Pusher https://pusher.com/docs

You can do this with Socket Programming like Laravel WebSockets or Use node.js with socket.io package. 您可以使用Laravel WebSockets之类的套接字编程来完成此操作,也可以将node.js与socket.io包一起使用。 Socket.io with Node.js is easy to learn. 带有Node.js的Socket.io很容易学习。 https://socket.io/get-started/chat https://socket.io/get-started/chat

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

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