jquery ajax responses?

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

jquery ajax responses?

sol tourne

hello -- 

I would appreciate help for what seems like a simple ajax procedure: submitting a value, capturing the response and displaying that response. More concretely, I have a simplified test page with just an input (say textarea), a div, and a button. When the button is clicked, I want it to grab the content of the input, ajax it to the seaside server and then display the response of the ajax call in the div. What would be the simplest and most elegant way of achieving that?

thanks!
ts


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

Re: jquery ajax responses?

sol tourne

To illustrate the question better, here is the seaside code and what it is lacking:

renderContentOn: html

html textArea
  id: #tainput;
  callback: [:intext | self translate: intext].

html div
  id: 'results';
  with: 'Translated text will come here'.
 
html button type: 'button';
  onClick: (html jQuery ajax
     onSuccess: (
       "--> here is where I need to grab the result of the callback above (the translated text),
            instead of showing the raw submitted value as below  <--"
       (html jQuery: #'results') text: (html jQuery: #tainput) value);
     serialize: (html jQuery: '#tainput'));
  with: 'Translate'.


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

Re: jquery ajax responses?

Johan Brichau-2
Hi,

You can pass values between callbacks via temporary variables (or instance variables too).
There are multiple ways of getting this done in the onClick handler. For example:

renderContentOn: html
| translatedText |

html textArea
  id: #tainput;
  callback: [:intext | translatedText := self translate: intext].

html div
  id: 'results';
  with: 'Translated text will come here'.

html button
  bePush;
  onClick: (html jQuery ajax
                        serialize: (html jQuery id: #tainput');
                        onSuccess: ((html jQuery id: 'results') load:[:r | r render: translatedText]));
 with: 'Translate'.

On 16 Feb 2014, at 19:50, [hidden email] wrote:

> renderContentOn: html
>
> html textArea
>  id: #tainput;
>  callback: [:intext | self translate: intext].
>
> html div
>  id: 'results';
>  with: 'Translated text will come here'.
>
> html button type: 'button';
>  onClick: (html jQuery ajax
>     onSuccess: (
>       "--> here is where I need to grab the result of the callback above (the translated text),
>            instead of showing the raw submitted value as below  <--"
>       (html jQuery: #'results') text: (html jQuery: #tainput) value);
>     serialize: (html jQuery: '#tainput'));
>  with: 'Translate'.
>
>
> Thanks for any pointer!
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

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

Re: jquery ajax responses?

sol tourne

Thanks Johan! That was the simple trick I was looking for.

(for the record, my Seaside 3.0.6 in Squeak 4.3 had no #load: in
JQueryInstance, so substituting the relevant line below did it)

       onSuccess: ((html jQuery id: 'results') load html: [:r | r render: translatedText]));


> There are multiple ways of getting this done in the onClick handler. For example:
>
> renderContentOn: html
> | translatedText |
>
> html textArea
>   id: #tainput;
>   callback: [:intext | translatedText := self translate: intext].
>
> html div
>   id: 'results';
>   with: 'Translated text will come here'.
>
> html button
>   bePush;
>   onClick: (html jQuery ajax
> serialize: (html jQuery id: #tainput');
> onSuccess: ((html jQuery id: 'results') load:[:r | r render: translatedText]));
>  with: 'Translate'.
>
> On 16 Feb 2014, at 19:50, [hidden email] wrote:
>
> > renderContentOn: html
> >
> > html textArea
> >  id: #tainput;
> >  callback: [:intext | self translate: intext].
> >
> > html div
> >  id: 'results';
> >  with: 'Translated text will come here'.
> >
> > html button type: 'button';
> >  onClick: (html jQuery ajax
> >     onSuccess: (
> >       "--> here is where I need to grab the result of the callback above (the translated text),
> >            instead of showing the raw submitted value as below  <--"
> >       (html jQuery: #'results') text: (html jQuery: #tainput) value);
> >     serialize: (html jQuery: '#tainput'));
> >  with: 'Translate'.
> >
> >
> > Thanks for any pointer!
> > _______________________________________________
> > seaside mailing list
> > [hidden email]
> > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: jquery ajax responses?

Johan Brichau-2
Ha yes, that's what I get when programming Smalltalk in an email client ;-)

glad you figured it out

Johan

On 17 Feb 2014, at 00:16, [hidden email] wrote:

>
> Thanks Johan! That was the simple trick I was looking for.
>
> (for the record, my Seaside 3.0.6 in Squeak 4.3 had no #load: in
> JQueryInstance, so substituting the relevant line below did it)
>
>       onSuccess: ((html jQuery id: 'results') load html: [:r | r render: translatedText]));
>
>
>> There are multiple ways of getting this done in the onClick handler. For example:
>>
>> renderContentOn: html
>> | translatedText |
>>
>> html textArea
>>  id: #tainput;
>>  callback: [:intext | translatedText := self translate: intext].
>>
>> html div
>>  id: 'results';
>>  with: 'Translated text will come here'.
>>
>> html button
>>  bePush;
>>  onClick: (html jQuery ajax
>> serialize: (html jQuery id: #tainput');
>> onSuccess: ((html jQuery id: 'results') load:[:r | r render: translatedText]));
>> with: 'Translate'.
>>
>> On 16 Feb 2014, at 19:50, [hidden email] wrote:
>>
>>> renderContentOn: html
>>>
>>> html textArea
>>> id: #tainput;
>>> callback: [:intext | self translate: intext].
>>>
>>> html div
>>> id: 'results';
>>> with: 'Translated text will come here'.
>>>
>>> html button type: 'button';
>>> onClick: (html jQuery ajax
>>>    onSuccess: (
>>>      "--> here is where I need to grab the result of the callback above (the translated text),
>>>           instead of showing the raw submitted value as below  <--"
>>>      (html jQuery: #'results') text: (html jQuery: #tainput) value);
>>>    serialize: (html jQuery: '#tainput'));
>>> with: 'Translate'.
>>>
>>>
>>> Thanks for any pointer!
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

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

Re: jquery ajax responses?

jtuchel
So your mail client has remote debugging disabled? ;-)

Am 17.02.14 20:32, schrieb Johan Brichau:
> Ha yes, that's what I get when programming Smalltalk in an email client ;-)
>
> glad you figured it out
>
> Johan
>
> On 17 Feb 2014, at 00:16, [hidden email] wrote:
>
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside