[Seaside] onSuccess: problem

Ramon Leon ramon.leon at allresnet.com
Sat May 10 00:34:46 UTC 2008

> Hi all,
> I'm having problems with html request... onSuccess:, this is 
> what i'm doing:
> 	html anchor
> 		class: #eventRefresh;
> 		onClick: (
> 			(html request 
> 				callback: [ Transcript show: 
> 'REQ'; cr ]; 
> 				onSuccess: 'window.alert("OK")';
> 				onFailure: 'window.alert("Failure")'));
> 		with: [ html image url: SushiLibrary / #addPng ]
> This is rendering all ok ('REQ' is being written on 
> transcript window) 
> ... but onSuccess (or onFailure) is not being called after it...
> This is de javascript generated with that call:
> new 
> Ajax.Request('http://localhost:8080/seaside/Sushimoto',{'onSuc
> cess':function(){'window.alert("OK")'},'onFailure':function(){
> 'window.alert("Failure")'},'parameters':['_s=BeRHEehLgPOyfdJU'
> ,'_k=zvZqQkjr','11'].join('&')})

onSuccess: (html alert: 'OK')

If you look at how #alert: is implemented...

alert: anObject
	self add: (SUStream new
		nextPutAll: 'alert';
		argument: anObject;

Then you'll see how to use SUStream manually to feed hand written JavaScript
into #onSuccess:.  Scriptaculous events like #onSuccess: do not work like
Seaside events like #onClick: or #onChange:.  Seaside events assume they're
being handed JavaScript and they just run whatever you give them, but
Scriptaculous events call #asFunction on whatever you give them, so when you
give them a string, they wrap a function around it...


Which basically won't do anything.  So if you want hand written JavaScript,
do this...

onSuccess: (SUStream on: 'window.alert("OK")')

And it'll work.

Ramon Leon

More information about the seaside mailing list