Server Sent Event / EventSource with node.js (express)

后端 未结 1 1555
小鲜肉
小鲜肉 2020-12-10 07:58

I\'m trying to send JSON data to the browser with SSE but I can\'t seem to get it right and I don\'t know why.

Server side looks like this:

var expre         


        
相关标签:
1条回答
  • 2020-12-10 08:33

    Try sending proper JSON (testdata isn't quoted in your output):

    res.write('data: {"msg": "'+ testdata +'"}\n\n');
    

    But preferably:

    res.write('data: ' + JSON.stringify({ msg : testdata }) + '\n\n');
    
    0 讨论(0)
提交回复
热议问题