Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventSource's response has a MIME type ("text/plain") that is not "text/event-stream"

EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.

Why I'm getting this error when sending a request from javascript to servlet?

like image 778
bashi12 Avatar asked May 04 '16 20:05

bashi12


1 Answers

You need to set the header of the message before sending it:

  response.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
  });

You can follow this article for more information: https://www.html5rocks.com/en/tutorials/eventsource/basics/

like image 63
Martin Chaov Avatar answered Oct 21 '22 08:10

Martin Chaov