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?
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?
Share Improve this question edited Jul 31, 2021 at 14:00 Parsa x86 1,1097 silver badges16 bronze badges asked May 4, 2016 at 20:00 Leshan WijegunawardanaLeshan Wijegunawardana 1911 gold badge1 silver badge5 bronze badges 1- Are you using webpack's hot loading? If a route is being handled before the hot loader can use it, then this is how the hot loader plains. Additionally, if you've loaded the hot loader to production, this error can occur as well. – crthompson Commented Jun 14, 2017 at 14:53
1 Answer
Reset to default 2You 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./en/tutorials/eventsource/basics/