onSuccess: problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

onSuccess: problem

EstebanLM
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',{'onSuccess':function(){'window.alert("OK")'},'onFailure':function(){'window.alert("Failure")'},'parameters':['_s=BeRHEehLgPOyfdJU','_k=zvZqQkjr','11'].join('&')})

I

asked at #prototype irc channel and someone tell me that I have to
remove de ' of the 'onSuccess' (and I suppose is the same in the
generated function) but i don't know how to do this (seems to has
something to do with SUStream encode:to:, but if i remove the $' from
the encoding, errors start to appear everywhere.

I don't know how to proceed from here...

I'm using Seaside2.8a1-lr.541 and Scriptaculous-mb.239 (I tried with
lr.540 too) on a 3.10 image.

Thanks,
Esteban


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: onSuccess: problem

Ramon Leon-5
 

> 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;
                yourself)

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...

function(){'window.alert("Failure")'}

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
http://onsmalltalk.com

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: onSuccess: problem

EstebanLM
It is so easy! I'm feel like a dumb... I tried everything, except that.
Thanks!

Esteban

On 2008-05-09 21:34:46 -0300, "Ramon Leon" <[hidden email]> said:

>
>> 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;
> yourself)
>
> 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...
>
> function(){'window.alert("Failure")'}
>
> 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
> http://onsmalltalk.com



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: onSuccess: problem

Lukas Renggli
In reply to this post by Ramon Leon-5
>  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...
>
>  function(){'window.alert("Failure")'}

The reason for this is that Scriptaculous "translates" Smalltalk to
JavaScript. If you put a string literal into a JavaScript object it is
transformed to a JavaScript string with the propre escaping of special
chars, etc.

As Ramon pointed out you need SUStream to tell a stream to be emitted verbatim.

Personally I prefer the logging framework built into all modern
webbrowser (Safari, FireFox) over using "alert()". It is not only more
convenient to get the message, but also much simpler to use:

    onSuccess: (html logger errror: 'Failure')

There are many other variateions. See the SULogger class.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside