Server sent event in Laravel 5 throwing an error "EventSource's response has a MIME type..." -
i writing code show notifications encountering error. code follows:
function notify() { $response = new symfony\component\httpfoundation\streamedresponse(function() { while (true) { $notification = notification::where('user_id', '=', auth::user()->id)->get(); echo 'data: ' . json_encode($notification) . "\n\n"; ob_flush(); flush(); sleep(3); } }); $response->headers->set('content-type', 'text/event-stream'); return $response; }
and in view have added javascript follows:
<script type="text/javascript"> var es = new eventsource("<?php echo action('notificationcontroller@notify'); ?>"); es.addeventlistener("message", function(e) { arr = json.parse(e.data); //apply effect on change, blinking color of modified cell... // } }, false);
the error :
eventsource's response has mime type ("text/html") not "text/event-stream". aborting connection.
how can solve it? writing code tutorial server-sent-events-example-laravel.
Comments
Post a Comment