Here is an example.
Keep in mind that the .chat-reply class has a click event handler associated with it.
HTML (response button):
<div class="container"> <a href="#" class="btn small chat-reply">Reply</a> </div>
This jQuery function is called when someone clicks the other button, which sends a message to the server for storage in the database. This is done using ajax and succeeds. In the aforementioned .ajax () success () callback, this function is called:
$.ajax({ type : 'GET', url : '/some_controller/some_method', success : function(data) { $('.container').replaceWith(data); } });
The "data" in the previous callback will be replaced by the whole .container div, including the .chat-reply child button. After this replaceWith (), the click event is no longer attached to the button.
Logically, I am trying to have the end user post a message on the timeline, then display this message on the timeline without to refresh the screen.
source share