<div dir="ltr">Hi guys,<div><br></div><div>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. </div><div><br></div><div>I was using #script together with #html: while Esteban was using #onSuccess:/#onError: with #load and #html:</div><div><br></div><div>I created a class for testing the differences. Very simple:</div><div><br></div><div><div>renderContentOn: html</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>self renderMyDivOn: html.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>html form: [ </div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>html button</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>bePush; </div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>onClick: <b>(html jQuery ajax</b></div><div><b><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span> <span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>script: [ :s | </b><b>s << ((s jQuery id: 'myDivId' ) html: [:r | </b><b>self renderMyDivOn: r. </b><b>]) </b><b>]</b></div><div><b><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>);</b></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>value: 'Test with #script: '.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>html button</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>bePush; </div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>onClick: <b>(html jQuery ajax</b></div><div><b><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span>callback: [ ];</b></div><div><b><span class="gmail-Apple-tab-span" style="white-space:pre">                                        </span>onSuccess: ( (html jQuery id: 'myDivId') load html: [ :r | self renderMyDivOn: r. ] ) </b></div><div><b><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span></b><b>);</b></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>value: 'Test with #onSuccess:'.<span class="gmail-Apple-tab-span" style="white-space:pre">                </span> </div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>]</div></div><div><br></div><div><br></div><div>And</div><div><br></div><div><div>renderMyDivOn: html</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>html div</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>id: 'myDivId';</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>with: [ html text: DateAndTime now greaseString. ]</div></div><div><br></div><div><br></div><div>Both solutions works. But of course, they are different. The generated HTML is different too of course:</div><div><br></div><div><div><div><form accept-charset="utf-8" method="post" action="/reps?_s=pbHnnKA9Ys-E9FtR&amp;_k=Wktdp8ek0iMZdSUY"></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span><b><button onclick="$.ajax({&quot;dataType&quot;:&quot;script&quot;,&quot;url&quot;:&quot;/reps&quot;,&quot;data&quot;:[&quot;_s=pbHnnKA9Ys-E9FtR&quot;,&quot;_k=Wktdp8ek0iMZdSUY&quot;,&quot;156&quot;].join(&quot;&amp;&quot;)})" type="button" class="button">Test with #script:</button></b></div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span> <b><button onclick="$.ajax({&quot;url&quot;:&quot;/reps&quot;,&quot;data&quot;:[&quot;_s=pbHnnKA9Ys-E9FtR&quot;,&quot;_k=Wktdp8ek0iMZdSUY&quot;,&quot;157&quot;].join(&quot;&amp;&quot;),&quot;success&quot;:function(){$(&quot;#myDivId&quot;).load(&quot;/reps&quot;,[&quot;_s=pbHnnKA9Ys-E9FtR&quot;,&quot;_k=Wktdp8ek0iMZdSUY&quot;,&quot;158&quot;].join(&quot;&amp;&quot;))}})" type="button" class="button">Test with #onSuccess:</button></b></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span></form></div></div></div><div><br></div><div><br></div><div>I am not an AJAX expert, so I wonder what are the differences, which is the recommended approach, and why.</div><div><br></div><div>Thank you very much in advance. </div><div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br></div>
</div></div>