简体   繁体   中英

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.

ui for call.blade.php 叫ui

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

<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

<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. Socket.io with Node.js is easy to learn. https://socket.io/get-started/chat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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