简体   繁体   中英

ajax: How to post a message without reloading the page?

could 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM