javascript - Retrieve data from server with SSE named something else than "data:" -
so i'm writing basic custom jquery plugin handle animating progress bars based on server-sent events (as now: plan on handling websocket , long-polling ajax too).
i'm willing know if there way data sent server named differently. until now, have read server must output like:
header('content-type: text/event-stream'); header('cache-control: no-cache'); for($i = 0; $i < 100; $i++) { echo 'data:'.$i."\n\n"; // must data: , not else! flush(); sleep(1); }
so can retrieved using
var stream = new eventsource('/api'); stream.onmessage = function(e) { console.log(e.data); // outputs $i sent server every second }
therefore, i'm wondering data sent server has named data:
read client-side or can have name? (and read client-side e.anothername
). not go towards creating json object server-side complicate manually setting plugin.
the purpose behind is, in order make progress bar progress, need percentage can calculated having maximum value of $i
server-side , current value. if can think of way have percentage without outputting total through first event, i'm willing know.
thanks.
'data:' compulsory sse support 'id' , 'event' may in case, check link
Comments
Post a Comment