views:

40

answers:

3

How do I call a function on every update? Below is what I tried. It doesn't work. The function itself works fine when I execute it alone.

new Ajax.PeriodicalUpdater('chatMessages', 'chat/receive_chat',
        {
                method: 'post',
                parameters: {lId: latestId},
                insertion: Insertion.Bottom,
                frequency: 2,
                decay: 2,
                Onsuccess: val = function(){$('chatMessages').scrollTop = $('chatMessages').scrollHeight;}
        });
+1  A: 

You have an assignment for onsuccess. What you need is either a reference to a function or inline function.

onsuccess: function(){$('chatMessages').scrollTop = $('chatMessages').scrollHeight;}
// or
onsuccess: my_callback_func
Jason McCreary
I tried this as well to no avail.
Josh
Check the docs, I don't know if `onsuccess` is a valid callback. I moved to jQuery earlier this year ;)
Jason McCreary
@Jason and @Ryley were both correct. There was a typo, it should be "onSuccess" and there should be no assignment for the onSuccess property just a callback function. Here is a link to a JSFiddle that is working correctly: http://www.jsfiddle.net/subhaze/FfvXt/
subhaze
@subhaze Thanks for the clarification. I knew it wasn't `Onsuccess`, but should have checked the docs to provide a thorough answer.
Jason McCreary
+1  A: 

Is this as simple as a case-sensitivity issue?

You have:

Onsuccess: function(){...}

Should it be:

onSuccess: function(){...}
Ryley
+2  A: 

Here is a working example: JSFiddle Example

subhaze
+1 for the example. You should have made your own answer instead of the comment. You deserved the green checkmark ;)
Jason McCreary
Thanks! Thought about that after I had commented, figured it was worth posting anyhow :)
subhaze