<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 24, 2016 at 3:48 AM, Johan Brichau <span dir="ltr">&lt;<a href="mailto:johan@inceptive.be" target="_blank">johan@inceptive.be</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mariano,<br></blockquote><div><br></div><div>Hi Johan, Thanks for answering. My answers below. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
First button does a single ajax call and responds a js script.<br>
Second button does two ajax calls, first one without a response content, second one with a html response content.<br>
<br></blockquote><div><br></div><div>But which of the called methods generate each of both ajax calls? #ajax and #load ?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Both achieve the same end result but the second one requires two request-response cycles to your server.<br>
The second one will thus achieve the end result slower than the first one.<br>
<br>
We typically also try to optimize as much as possible into single ajax requests.<br></blockquote><div><br></div><div>OK. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Mind that you _can_ combine a single primary and multiple secondary callback blocks into a single ajax call.<br>
A primary callback is a callback that responds a content to the client (#script:, #html:, #json:, #text, ….)<br>
A secondary callback is a callback that does not respond content (#callback:value:, #callback:passengers:, #callback:json: , …)<br>
There is an exception to this rule, #callback: is implemented in the Seaside jQuery binding as a primary callback, even if it does not return any content.<br>
<br>
Although for this example, I would actually write it as follows, because the #callback: block is a primary callback.<br>
<br>
                html button<br>
                        bePush;<br>
                        onClick: (html jQuery id: ‘myDivId’ load html: [:r | | … do some other stuff …. then ... self renderMyDivOn: r.  ] )<br>
                        value: ‘Test’<br>
<br></blockquote><div><br></div><div>OK. But you said that #callback: was a primary callback and we cannot have multiple primary callbacks in one ajax request. So my above example, where I was using #callback:  .. let&#39;s say I have  &quot;callback: [ self doAnotherStuff ]&quot;. So in this example (with the second solution), I would actually be having THREE ajax calls?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now, it also depends of the ‘myDivId’ is known when rendering the button or not, but in this simple example this would yield the same result ;)<br>
<br></blockquote><div><br></div><div>mmmmm could you mind explaining an example  of this and how both solutions are different from this regard? </div><div><br></div><div>Thanks in advance Johan!</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
cheers<br>
Johan<br>
<div><div class="h5"><br>
&gt; On 24 Sep 2016, at 04:19, Mariano Martinez Peck &lt;<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi guys,<br>
&gt;<br>
&gt; Today I have a discussion with Esteban Maringolo and it looks we are both doing something different for a classical AJAX example. Consider the typical example of a click on a button that should trigger the re-render of a given DIV.<br>
&gt;<br>
&gt; I was using #script together with #html:  while Esteban was using #onSuccess:/#onError: with #load and #html:<br>
&gt;<br>
&gt; I created a class for testing the differences. Very simple:<br>
&gt;<br>
&gt; renderContentOn: html<br>
&gt;       self renderMyDivOn: html.<br>
&gt;       html form: [<br>
&gt;               html button<br>
&gt;                       bePush;<br>
&gt;                       onClick: (html jQuery ajax<br>
&gt;                                                               script: [ :s |   s &lt;&lt; ((s jQuery id: &#39;myDivId&#39; ) html: [:r |  self renderMyDivOn: r. ]) ]<br>
&gt;                       );<br>
&gt;                       value: &#39;Test with #script: &#39;.<br>
&gt;<br>
&gt;               html button<br>
&gt;                       bePush;<br>
&gt;                       onClick: (html jQuery ajax<br>
&gt;                                       callback: [  ];<br>
&gt;                                       onSuccess: (  (html jQuery id: &#39;myDivId&#39;) load html: [ :r | self renderMyDivOn: r.  ] )<br>
&gt;                               );<br>
&gt;                       value: &#39;Test with #onSuccess:&#39;.<br>
&gt;       ]<br>
&gt;<br>
&gt;<br>
&gt; And<br>
&gt;<br>
&gt; renderMyDivOn: html<br>
&gt;<br>
&gt;       html div<br>
&gt;               id: &#39;myDivId&#39;;<br>
&gt;               with: [ html text: DateAndTime now greaseString. ]<br>
&gt;<br>
&gt;<br>
&gt; Both solutions works. But of course, they are different. The generated HTML is different too of course:<br>
&gt;<br>
&gt; &lt;form accept-charset=&quot;utf-8&quot; method=&quot;post&quot; action=&quot;/reps?_s=pbHnnKA9Ys-<wbr>E9FtR&amp;amp;_k=Wktdp8ek0iMZdSUY&quot;<wbr>&gt;<br>
&gt;                               &lt;button onclick=&quot;$.ajax({&amp;quot;<wbr>dataType&amp;quot;:&amp;quot;script&amp;<wbr>quot;,&amp;quot;url&amp;quot;:&amp;quot;/<wbr>reps&amp;quot;,&amp;quot;data&amp;quot;:[&amp;<wbr>quot;_s=pbHnnKA9Ys-E9FtR&amp;quot;<wbr>,&amp;quot;_k=Wktdp8ek0iMZdSUY&amp;<wbr>quot;,&amp;quot;156&amp;quot;].join(&amp;<wbr>quot;&amp;amp;&amp;quot;)})&quot; type=&quot;button&quot; class=&quot;button&quot;&gt;Test with #script:&lt;/button&gt;<br>
&gt;<br>
&gt;                                &lt;button onclick=&quot;$.ajax({&amp;quot;url&amp;<wbr>quot;:&amp;quot;/reps&amp;quot;,&amp;quot;<wbr>data&amp;quot;:[&amp;quot;_s=<wbr>pbHnnKA9Ys-E9FtR&amp;quot;,&amp;quot;_<wbr>k=Wktdp8ek0iMZdSUY&amp;quot;,&amp;<wbr>quot;157&amp;quot;].join(&amp;quot;&amp;<wbr>amp;&amp;quot;),&amp;quot;success&amp;<wbr>quot;:function(){$(&amp;quot;#<wbr>myDivId&amp;quot;).load(&amp;quot;/<wbr>reps&amp;quot;,[&amp;quot;_s=<wbr>pbHnnKA9Ys-E9FtR&amp;quot;,&amp;quot;_<wbr>k=Wktdp8ek0iMZdSUY&amp;quot;,&amp;<wbr>quot;158&amp;quot;].join(&amp;quot;&amp;<wbr>amp;&amp;quot;))}})&quot; type=&quot;button&quot; class=&quot;button&quot;&gt;Test with #onSuccess:&lt;/button&gt;<br>
&gt;                       &lt;/form&gt;<br>
&gt;<br>
&gt;<br>
&gt; I am not an AJAX expert, so I wonder what are the differences, which is the recommended approach, and why.<br>
&gt;<br>
&gt; Thank you very much in advance.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Mariano<br>
&gt; <a href="http://marianopeck.wordpress.com" rel="noreferrer" target="_blank">http://marianopeck.wordpress.<wbr>com</a><br>
</div></div>&gt; ______________________________<wbr>_________________<br>
&gt; seaside mailing list<br>
&gt; <a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.<wbr>squeakfoundation.org</a><br>
&gt; <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" rel="noreferrer" target="_blank">http://lists.squeakfoundation.<wbr>org/cgi-bin/mailman/listinfo/<wbr>seaside</a><br>
<br>
______________________________<wbr>_________________<br>
seaside mailing list<br>
<a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.<wbr>squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" rel="noreferrer" target="_blank">http://lists.squeakfoundation.<wbr>org/cgi-bin/mailman/listinfo/<wbr>seaside</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br></div>
</div></div>