Reputation: 330
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.
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.
Upvotes: 2
Views: 2762
Reputation: 740
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
Upvotes: 1
Reputation: 9
You have to use Web Socket services like Pusher https://pusher.com/docs
Upvotes: 1