1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Open the requested event_source.php in the browser to view, as shown below:
I don’t understand what kind of response type the EventStream here is..., why the onmessage method never receives any data (because no information is received under the EventStream column on the way...), what is going on? ? What I output in the background is a string. Do I need to perform type conversion on the string? ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Open the requested event_source.php in the browser to view, as shown below:
I don’t understand what kind of response type the EventStream here is..., why the onmessage method never receives any data (because no information is received under the EventStream column on the way...), what is going on? ? What I output in the background is a string. Do I need to perform type conversion on the string? ?
Because the format of the text output in your echo is wrong.
The content of each echo must be in the following format
1 2 |
|
field can be any one of data, event, id, retry
value is the data payload
Your example here should be changed to
1 2 |
|
Reference:
https://www.mxgw.info/t/serve...
http://javascript.ruanyifeng....
https://developer.mozilla.org...
There is no php identifier in php?
When accessing the php file in the browser, js will definitely not receive the message. To create an html, access the html in the browser.