[Seaside] [AJAX] #script: & #html: vs #onSuccess: & #load & #html:
Mariano Martinez Peck
marianopeck at gmail.com
Sat Sep 24 02:19:14 UTC 2016
Hi guys,
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.
I was using #script together with #html: while Esteban was using
#onSuccess:/#onError: with #load and #html:
I created a class for testing the differences. Very simple:
renderContentOn: html
self renderMyDivOn: html.
html form: [
html button
bePush;
onClick: *(html jQuery ajax*
* script: [ :s | **s << ((s jQuery id: 'myDivId' ) html: [:r | **self
renderMyDivOn: r. **]) **]*
* );*
value: 'Test with #script: '.
html button
bePush;
onClick: *(html jQuery ajax*
* callback: [ ];*
* onSuccess: ( (html jQuery id: 'myDivId') load html: [ :r | self
renderMyDivOn: r. ] ) *
*);*
value: 'Test with #onSuccess:'.
]
And
renderMyDivOn: html
html div
id: 'myDivId';
with: [ html text: DateAndTime now greaseString. ]
Both solutions works. But of course, they are different. The generated HTML
is different too of course:
<form accept-charset="utf-8" method="post"
action="/reps?_s=pbHnnKA9Ys-E9FtR&_k=Wktdp8ek0iMZdSUY">
*<button
onclick="$.ajax({"dataType":"script","url":"/reps","data":["_s=pbHnnKA9Ys-E9FtR","_k=Wktdp8ek0iMZdSUY","156"].join("&")})"
type="button" class="button">Test with #script:</button>*
*<button
onclick="$.ajax({"url":"/reps","data":["_s=pbHnnKA9Ys-E9FtR","_k=Wktdp8ek0iMZdSUY","157"].join("&"),"success":function(){$("#myDivId").load("/reps",["_s=pbHnnKA9Ys-E9FtR","_k=Wktdp8ek0iMZdSUY","158"].join("&"))}})"
type="button" class="button">Test with #onSuccess:</button>*
</form>
I am not an AJAX expert, so I wonder what are the differences, which is the
recommended approach, and why.
Thank you very much in advance.
--
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20160923/c6668e64/attachment.htm
More information about the seaside
mailing list