ajax: How to post a message without reloading the page?
co开发者_开发技巧uld you explain the basis on how to post a message (like facebook or even stackoverflow) that don't reload their page but they shows the comment instantly ?
How that works?
Add1:
I know how ajax works, I would know how to do this particular stuff with ajax, ie posting a comment to a database and showing it without reloading the page
The javascript code http posts to a backend script (page) that you have set up. That page does stuff and then returns the result for the javascript to use for modifying the DOM on the page.
the entire point of Ajax is to be asynchronous. This means that the request fires, but a user can still use the page from which the Ajax is invoked. When the response comes back, the javascript handling the ajax will update the relevant part of the page. So how to do it, really basic and simple
1) have a button with a javascript handler on it. When clicked, the button js
2) executes the ajax request. When the request returns
3) javascript updates the page, with the comment in your example.
精彩评论