Basic question about AJAX and callbacks

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

Basic question about AJAX and callbacks

Mariano Martinez Peck
Hi guys,

I am trying to have a button that instead of doing a form submit and a whole page render, simply serializes the form and tries to re-render something. My code is this:

html tbsButton
bePrimary;
bePush;
value: 'Save';
onClick:  
               (html jQuery ajax
                       serializeChildren: (html jQuery: '#myFormID');
callback: [ 
self halt. 
]
;
script: [ :s | self halt. s << (s jQuery id: ('tr1')) replaceWith:[:r | r html: 'mariano' ]]
)


So I am declaring this button which is #bePush (to avoid a whole page render). Then with #serializeChildren I serialize the form (is this correct?), and finally with #script: I try to re-render again that row (in the example I simply display 'mariano'). 'tr1' is the correct id of the correct TR. 

I want #script: to be called AFTER the ajax callback. But it seems that if I define a #script: then the AJAX callback is not executed :( If I don't put the #script:, it is called...

Also..when I click on that button, in the FF dev console I see "Use of attributes' specified attribute is deprecated. It always returns true.". 

Any ideas what I am doing wrong? Probably many things...

Thanks in advance, 


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

Re: Basic question about AJAX and callbacks

Esteban A. Maringolo
Maybe you should use #onComplete: instead of #script: in your JQAjax object.
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Basic question about AJAX and callbacks

Mariano Martinez Peck
ouuuuch

sorrryyyy by bad hahahhaha. Very funny. I will explain later. Don't loose your time.

Best, 



On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo <[hidden email]> wrote:
Maybe you should use #onComplete: instead of #script: in your JQAjax object.
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



--
Mariano
http://marianopeck.wordpress.com

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

Re: Basic question about AJAX and callbacks

Mariano Martinez Peck
Well...not there yet...now I am able to render the new table row with all the 'mariano'. And the row itself seems to reflect changes (the callback of the ajax is really executed). The problem now is that I don't know how to make my render script to happen AFTER the callback of the ajax. I tried #script:  , #onComplete: and #onSuccess:  (just in case). What I need is to make the ajax call, serialize the form, execute the ajax callback, and then do the replace of the tr (with a script). 

The only one that seems to be executed later is #script: but when I do this, the callback of the ajax is not executed. 

Any ideas?

Thanks,


On Thu, Jul 10, 2014 at 6:22 PM, Mariano Martinez Peck <[hidden email]> wrote:
ouuuuch

sorrryyyy by bad hahahhaha. Very funny. I will explain later. Don't loose your time.

Best, 



On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo <[hidden email]> wrote:
Maybe you should use #onComplete: instead of #script: in your JQAjax object.
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



--
Mariano
http://marianopeck.wordpress.com



--
Mariano
http://marianopeck.wordpress.com

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

Re: Basic question about AJAX and callbacks

Winfried Jacobs-2
In reply to this post by Mariano Martinez Peck
(sorry if this message comes up multiple times)

Hello Mariano,

JQAjax>>script: ist a callback, so you don't need both #callback: and #script: .
Instead, you should merge both of your callback blocks into one:

     html jQuery ajax
         serializeChildren: (html jQuery: '#myFormID');
         script: [ :s |
                 "code from your first #callback: goes in here."
                 "..."

                 self halt. s << (s jQuery id: ('tr1')) replaceWith:[:r | r
html: 'mariano' ]
                 ]



One possible reason why your code doesn't work: #callback: and #script: are
primary callbacks, but you can only register one primary callback for an ajax
object.

However, you could register multiple secondary callbacks like #callback:value:
#callback:json: etc.  But in your case, a secondary
callback is unnecessary.



Cheers
Winfried



> Mariano Martinez Peck <[hidden email]> hat am 11. Juli 2014 um 04:23
> geschrieben:
>
>  Well...not there yet...now I am able to render the new table row with all the
>'mariano'. And the row itself seems to reflect changes (the callback of the
>ajax is really executed). The problem now is that I don't know how to make my
>render script to happen AFTER the callback of the ajax. I tried #script:  ,
>#onComplete: and #onSuccess:  (just in case). What I need is to make the ajax
>call, serialize the form, execute the ajax callback, and then do the replace of
>the tr (with a script).
>   
>  The only one that seems to be executed later is #script: but when I do this,
>the callback of the ajax is not executed.
>   
>  Any ideas?
>   
>  Thanks,
>
>
>  On Thu, Jul 10, 2014 at 6:22 PM, Mariano Martinez Peck <[hidden email]
><mailto:[hidden email]> > wrote:
>    > >    ouuuuch
> >     
> >    sorrryyyy by bad hahahhaha. Very funny. I will explain later. Don't loose
> >your time.
> >     
> >    Best,
> >     
> >
> >
> >    On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo
> ><[hidden email] <mailto:[hidden email]> > wrote:
> >      > > > Maybe you should use #onComplete: instead of #script: in your
> >JQAjax object.
> > >      _______________________________________________
> > >      seaside mailing list
> > >      [hidden email]
> > ><mailto:[hidden email]>
> > >      http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> > >    > >
> >
> >     
> >    --
> >    Mariano
> >    http://marianopeck.wordpress.com
> >  >
>
>   
>  --
>  Mariano
http://marianopeck.wordpress.com
>  _______________________________________________
>  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: Basic question about AJAX and callbacks

Mariano Martinez Peck



On Fri, Jul 11, 2014 at 10:37 AM, Winfried Jacobs <[hidden email]> wrote:
(sorry if this message comes up multiple times)

Hello Mariano,

JQAjax>>script: ist a callback, so you don't need both #callback: and #script: .
Instead, you should merge both of your callback blocks into one:

     html jQuery ajax
         serializeChildren: (html jQuery: '#myFormID');
         script: [ :s |
                 "code from your first #callback: goes in here."
                 "..."

                 self halt. s << (s jQuery id: ('tr1')) replaceWith:[:r | r
html: 'mariano' ]
                 ]



Hi Winfried,

You know...yesterday night, just before going to sleep, I realized that indeed, I could put by "callback code" inside the very same #script: and then from there re-render (replaceWith...) from there. 
 

One possible reason why your code doesn't work: #callback: and #script: are
primary callbacks, but you can only register one primary callback for an ajax
object.


OK, I see. 
 
However, you could register multiple secondary callbacks like #callback:value:
#callback:json: etc.  But in your case, a secondary
callback is unnecessary.


OK, thanks for the explanation. I will read the web 2.0 chapter of the Dynamic Web Development..otherwise...why did I buy it? hahaha. 

Thanks, 
 


Cheers
Winfried



> Mariano Martinez Peck <[hidden email]> hat am 11. Juli 2014 um 04:23
> geschrieben:
>
>  Well...not there yet...now I am able to render the new table row with all the
>'mariano'. And the row itself seems to reflect changes (the callback of the
>ajax is really executed). The problem now is that I don't know how to make my
>render script to happen AFTER the callback of the ajax. I tried #script:  ,
>#onComplete: and #onSuccess:  (just in case). What I need is to make the ajax
>call, serialize the form, execute the ajax callback, and then do the replace of
>the tr (with a script).
>   
>  The only one that seems to be executed later is #script: but when I do this,
>the callback of the ajax is not executed.
>   
>  Any ideas?
>   
>  Thanks,
>
>
>  On Thu, Jul 10, 2014 at 6:22 PM, Mariano Martinez Peck <[hidden email]
><mailto:[hidden email]> > wrote:
>    > >    ouuuuch
> >     
> >    sorrryyyy by bad hahahhaha. Very funny. I will explain later. Don't loose
> >your time.
> >     
> >    Best,
> >     
> >
> >
> >    On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo
> ><[hidden email] <mailto:[hidden email]> > wrote:
> >      > > > Maybe you should use #onComplete: instead of #script: in your
> >JQAjax object.
> > >      _______________________________________________
> > >      seaside mailing list
> > >      [hidden email]
> > ><mailto:[hidden email]>
> > >      http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> > >    > >
> >
> >     
> >    --
> >    Mariano
> >    http://marianopeck.wordpress.com
> >  >
>
>   
>  --
>  Mariano
http://marianopeck.wordpress.com
>  _______________________________________________
>  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



--
Mariano
http://marianopeck.wordpress.com

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

Re: Basic question about AJAX and callbacks

Mariano Martinez Peck
Ok.... since we are already in this thread....is there any Javascript expert around?  What I need to do now goes outside my current limits...
I have the example I showed in this thread:

html anchor
class: 'btn btn-default btn-group-xs dropdown-toggle btn-xs'; 
onClick:  
                (html jQuery ajax
                        serialize: (html jQuery: '#reportTableForm');
script: [ :s |  
self doSomethingThin: anObject.
s << ((s jQuery id: ('tr',(self report indexFor: anObject) asString)) replaceWith:[:r | 
"here...can I get the text of the href of my THs of the TR of the tableHead?"
self report reRenderRow: anObject on: r.
]).
  ])

That is an anchor inside a cell of row, that serializes the form, then I do something with the row (anObject) and finally I re-render the row. OK?
Now....the question is...I also have some Javascript lib rendering the table (DataTables) which provides some plugins to, for example, re-order the columns, hide-show columns, etc... The same tool also allows to keep in the session, the "modifications" (columns reorder, hide/show columns etc), so....if the user has reordered columns or hide-show some, when I re-render the row, it is bad because in the server I have the "old" order etc.  The lib may provide a callback or hook to be send whenever the columns are reordered or hidden/shown but that is more complex to implement....   

My columns have href as the "title" (sorting), hence I already have this function:

var getCellText = function (elem) {
                    //get only the element text
                    return elem.contents().filter(function() {
                        return this.nodeValue;
                    }).text();
                };

Note that I do know the id of the TR. So I guess I should get the tableHead, then its TR, then get the list of TH and for each call that function. In any case....what I would need is that list and send it as argument to "self report reRenderRow: anObject on: r.". 
The problem is that I need to EXECUTE that javascript, get the return and use that for my re-render.

Maybe this is not possible...

Thanks in advance!




On Fri, Jul 11, 2014 at 11:10 AM, Mariano Martinez Peck <[hidden email]> wrote:



On Fri, Jul 11, 2014 at 10:37 AM, Winfried Jacobs <[hidden email]> wrote:
(sorry if this message comes up multiple times)

Hello Mariano,

JQAjax>>script: ist a callback, so you don't need both #callback: and #script: .
Instead, you should merge both of your callback blocks into one:

     html jQuery ajax
         serializeChildren: (html jQuery: '#myFormID');
         script: [ :s |
                 "code from your first #callback: goes in here."
                 "..."

                 self halt. s << (s jQuery id: ('tr1')) replaceWith:[:r | r
html: 'mariano' ]
                 ]



Hi Winfried,

You know...yesterday night, just before going to sleep, I realized that indeed, I could put by "callback code" inside the very same #script: and then from there re-render (replaceWith...) from there. 
 

One possible reason why your code doesn't work: #callback: and #script: are
primary callbacks, but you can only register one primary callback for an ajax
object.


OK, I see. 
 
However, you could register multiple secondary callbacks like #callback:value:
#callback:json: etc.  But in your case, a secondary
callback is unnecessary.


OK, thanks for the explanation. I will read the web 2.0 chapter of the Dynamic Web Development..otherwise...why did I buy it? hahaha. 

Thanks, 
 


Cheers
Winfried



> Mariano Martinez Peck <[hidden email]> hat am 11. Juli 2014 um 04:23
> geschrieben:
>
>  Well...not there yet...now I am able to render the new table row with all the
>'mariano'. And the row itself seems to reflect changes (the callback of the
>ajax is really executed). The problem now is that I don't know how to make my
>render script to happen AFTER the callback of the ajax. I tried #script:  ,
>#onComplete: and #onSuccess:  (just in case). What I need is to make the ajax
>call, serialize the form, execute the ajax callback, and then do the replace of
>the tr (with a script).
>   
>  The only one that seems to be executed later is #script: but when I do this,
>the callback of the ajax is not executed.
>   
>  Any ideas?
>   
>  Thanks,
>
>
>  On Thu, Jul 10, 2014 at 6:22 PM, Mariano Martinez Peck <[hidden email]
><mailto:[hidden email]> > wrote:
>    > >    ouuuuch
> >     
> >    sorrryyyy by bad hahahhaha. Very funny. I will explain later. Don't loose
> >your time.
> >     
> >    Best,
> >     
> >
> >
> >    On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo
> ><[hidden email] <mailto:[hidden email]> > wrote:
> >      > > > Maybe you should use #onComplete: instead of #script: in your
> >JQAjax object.
> > >      _______________________________________________
> > >      seaside mailing list
> > >      [hidden email]
> > ><mailto:[hidden email]>
> > >      http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> > >    > >
> >
> >     
> >    --
> >    Mariano
> >    http://marianopeck.wordpress.com
> >  >
>
>   
>  --
>  Mariano
http://marianopeck.wordpress.com
>  _______________________________________________
>  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



--
Mariano
http://marianopeck.wordpress.com



--
Mariano
http://marianopeck.wordpress.com

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