How to combine serialize and a load.

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

How to combine serialize and a load.

Timothy James Ziebart
Hi all,

In the following code I am trying to accomplish two things.  Update the
contents of "model region" on the server using serializeThis and then
render a div on the page using load.  I cannot  get them to work
together.   The serializeThis or load with the onChange: message works
fine alone but when I try to combine them I don't get the behavior I am
expecting.  Any suggestions?  Note the page element being loaded is not
the same as the select.

     html select
             id: html nextId;
             list: (self session findCodeByParent: 'region' type: 'region');
             selected: model region;
             callback: [ :value | self regionSelectionChanged: value ];
             onChange: (html jQuery ajax  serializeThis);
                 onAjaxComplete: ((html jQuery id: 's_results' ) load
html: [: r | self renderResultsOn: r]).

Thank you.

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

Re: How to combine serialize and a load.

Lukas Renggli
>    html select
>            id: html nextId;
>            list: (self session findCodeByParent: 'region' type: 'region');
>            selected: model region;
>            callback: [ :value | self regionSelectionChanged: value ];
>            onChange: (html jQuery ajax  serializeThis);
>                onAjaxComplete: ((html jQuery id: 's_results' ) load html: [:
> r | self renderResultsOn: r]).

1) #onAjaxComplete: is implemented on the jQuery object, not on the
WASelectTag and not on the JQAjax instance. #onAjaxComplete: is used
to register a global completion handler, there is also #onComplete: on
the JQAjax itself that is used to register for that particular
instance only.

2) You create two AJAX requests that are triggered one after each
other. While this generally works it is very inefficient because it
does two roundtrips to the server. If possible you should always
combine AJAX calls. In most cases this is possible.

Try something along:

   .. onChange: ((html jQuery id: 's_results') load
        serializeThis;
        html: [ :r | self renderResultsOn: r ])

That serializes AND renders the results in one AJAX call. You also
don't need the #onAjaxComplete: because this is just one AJAX call.

Lukas

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

Re: How to combine serialize and a load.

Timothy James Ziebart
Thank you Lukas.  When you see it done correctly it  becomes obvious.

On 30/01/10 02:44 AM, Lukas Renggli wrote:

>>     html select
>>             id: html nextId;
>>             list: (self session findCodeByParent: 'region' type: 'region');
>>             selected: model region;
>>             callback: [ :value | self regionSelectionChanged: value ];
>>             onChange: (html jQuery ajax  serializeThis);
>>                 onAjaxComplete: ((html jQuery id: 's_results' ) load html: [:
>> r | self renderResultsOn: r]).
>>      
> 1) #onAjaxComplete: is implemented on the jQuery object, not on the
> WASelectTag and not on the JQAjax instance. #onAjaxComplete: is used
> to register a global completion handler, there is also #onComplete: on
> the JQAjax itself that is used to register for that particular
> instance only.
>
> 2) You create two AJAX requests that are triggered one after each
> other. While this generally works it is very inefficient because it
> does two roundtrips to the server. If possible you should always
> combine AJAX calls. In most cases this is possible.
>
> Try something along:
>
>     .. onChange: ((html jQuery id: 's_results') load
>          serializeThis;
>          html: [ :r | self renderResultsOn: r ])
>
> That serializes AND renders the results in one AJAX call. You also
> don't need the #onAjaxComplete: because this is just one AJAX call.
>
> Lukas
>
>    

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