javascript - Using Server Sent Events in NodeJS not recieving data on client-side -


i have 1 webpage text input 1 webpage , want obtain information.

in client have this:

function login() {     webpage = document.getelementbyid("webpage").value;     alert(webpage);      source = new eventsource(         "http://localhost:8000/register?name="+webpage,          {'access-control-allow-origin' :'*'}     );      source.onmessage = function(event) {         var = event.data;         alert(a);     }; } 

in server have this:

response.writehead(200, {     'content-type' : 'text/event-stream; charset=utf-8',     'cache-control' : 'no-cache',     'connection' : 'keep-alive',     'access-control-allow-origin': '*' }); 

but, i'm trying obtain a , alert(a) doesn't nothing. idea what's problem in code? or how make work? suggestions in jquery welcome.

it seems haven't sent data server, setting headers doesn't much.

you need send events/data

res.write('event:data\n') 

you're using server sent events nodejs (something may have been unaware of @ time of asking) search around how use it. here's start.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -