[Seaside] hand-written javascript in Ajax

Lukas Renggli renggli at gmail.com
Thu Jun 5 09:05:34 UTC 2008

> I have a marker on the map which houses a link with an onclick handler
> called 'addLocation( "123456" );'.   So, I tried to define addLocation like
> this:
>                 html script: (' function addLocation( theId ) { ', ((
>                          html updater
>                         id: 'locations';
>                         callback: [ :v |
>                             locations add: ( myLocation new title: v ).
>                             self renderLocationsOn: html.
>                              ]
>                         value: (SUStream on: 'theId')) asJavascript ), '; }'
> ).
>                         ]
>                     ]
> This crashes my updater.  It does pass the value of theId properly as this
> is stored into the MyLocation collection.  But, it seems I need an html
> object renderer passed back to me.

You should not render within #callback:value:. Use a
rendering-callback to update your page.

Furthermore, pay attention that 'html' is not valid anymore (this html
stream has been sent out when the script was generated) when the
callback is triggered. Use the renderer that gets passed into the
render-callback. Slime detects that kind of problems.

html updater
   id: 'locations';
   callback: [ :v | locations add: v ] value: 'something';
   callback: [ :r | self renderLocationsOn: r ].

Please check out the class comments in SUAjax and subclasses. Also the
methods #callback:value: and #callback: are heavily documented.


Lukas Renggli

More information about the seaside mailing list