This is an OpenQuestion for me, but I’ll bet somebody knows…
Madrobby says: If you mean the callbacks, take a look at the respective API docs (perhaps they should be fleshed out more). Basically, the callbacks allow you to call any Javascript, and the Javascript is given the XMLHttpRequest object as ‘request’. For example, :complete => 'alert(request.responseText)' will show you the server response in a message box. Specialized event handling for DOM events is coming to prototype, and will allow you to easily add events to your DOM elements. You can take a look at this part of the autocomplete patch (but it will perhaps look slightly different in the end)
I believe he asking how to handle javascript events. How to make AJAX calls on mouseover, etc, without having to hand code the prototype calls yourself and using something like link_to_remote
The answer I think is to use ‘remote_function’ with the same parameters you pass to link_to_remote (excluding name).
Wam says: To be able to use callbacks, you have to create a javascript function embeding for example a remote_function tag, and add this function as eventlistener.
For example :
<script>
function whenclicked(e) {
//e is the event, google eventlistener javascript to know more about its properties
//e.target is the object that raised the event
<%= remote_function blablabla (see api about this) %>
}
</script>
And ensure that the following script is runned on page load :
<script>
//'event' may be click, mousedown, keydown ... look for addeventlistener to know more
$('somedivorlinkorbutton').addEventListener('event','whenclicked','false')
</script>
I hope it helps..
Category: Howto, Stub