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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -