Using php to update content in real time can be immediately displayed when a microblog is sent like Sina Weibo. Could you please give me some comments? How should I write this code ?? Using php to update content in real time can be immediately displayed when a microblog is sent like Sina Weibo. Could you please give me some comments? How should I write this code ??
Reply content:
Using php to update content in real time can be immediately displayed when a microblog is sent like Sina Weibo. Could you please give me some comments? How should I write this code ??
JavaScript
,Form
Form to makeOnsubmit
And then obtain the content in the input box.Ajax
POST to the backend. After the backend is successfully inserted into the databaseHTTP response header
Return201 Created
, Front-endJavaScript
Generate an HTML element from the POST text and insert it into the original DOM tree.
Every English word is a keyword. If you don't understand it, google it.
The real-time display of Sina Weibo is actually when the content is successfully published, the JS directly writes the content filtered and formatted on the server side to the page, the method is different from what @ yegle said.
The main reason is that the implementation of @ yegle requires that the JS end be able to implement the same filtering and processing of the content, but in fact, there are few scenarios where this can be done on Web 2.0 sites, the content is usually associated with other user data to have all the functions.
The reason why JS directly writes the content that has been processed by the server to the page is that Weibo's distribution takes time and what it just sent cannot be immediately displayed in the feed stream, therefore, this operation is available.