On the stackoverflow, there is a add comment functionality, which is done using ajax. I’m curious to know how that works. I understand that on add comment button, a ajax post request is sent to the server, but from his point I’m stuck.
Can u explain me how it works or send me to some web resuorces which explains it?
After clicking submit, the javascript does two things:
Sends the data back to the server via AJAX to be stored in the database and returns an “okay” back to the browser if the comment is successfully added/stored.
When the browser gets the “okay” response from the server via AJAX, another javascript function appends the data/text/comment to the existing HTML without having to reload the entire page. If the browser does not get the “okay”, the user may see an error message displayed instead.