[Seaside] jQuery Ajax: do something before and after

Joachim Tuchel jtuchel at objektfabrik.de
Mon Mar 25 18:58:42 UTC 2013


Hi Johan,

first of all: thanks fpr commenting. My code was just a simplification 
of what I want to achieve. I wanted to do the simplest thing that I 
could do for a before/after example, just to make sure I am not stuck 
somewhere completely different than I thought.

My real goal is/was to open a progress dialog during a longer running 
ajax call and show some success/failure information afterwards. This 
success/failure dialog should then answer: and return the the component 
the user came from. So sorry if my example as a whole didn't make sense.

In essence, I somehow completely failed to understand why the submit 
action of a form submit button would be happening before the ajax call 
is finished. Even though I know that ajax calls are asynchronous. The 
fact that I have onBeforeSend and anComplete handlers wrappered around 
it, doesn't make it any more synchronous of course. So your comment is 
absolutely spot on! Thanks for that.

Building on top of the "return: false" trick, I could solve my problem - 
at least in a manner good enough for a prototype.

Thanks again

Joachim


Am 24.03.13 13:57, schrieb Johan Brichau:
> Hi Joachim,
>
>> So this brings me to my next problem: How would I do one of the following (which I did in the submitButton's callback block):
>> * navigate to another component (usign show:, for example)
> Since the ajax callback in your code snippet is an ajax action callback, you will need to do something different to get at something like the component call behavior in Seaside.
> I have not actually tested this, but this is what I can think of:
>
> 	html submitButton
>               callback: [];
>               onClick: (((html jQuery ajax)
>                         onBeforeSend: ((html jQuery class: 'submit') hide);
>                         script: [:s | s << (s javascript callback:[self show: SomeComponent new])];
>                         onComplete: ((html jQuery class: 'submit') show)) return: false).
>
> But the snippet becomes a bit weird because you are triggering a full-page request (using #show:) _and_ you want to reshow the submit button on the previous page?
> If you wanted to have a full page rerender anyway, but only were trying to hide the submit button so it does not get clicked twice, you can do it like this:
>
> 	html submitButton
>               callback: [self show: WAMultiCounter new];
>               onClick: (html jQuery class: 'submit') hide
>
> The above assumes that the submit button is the nested in a form and that the browser triggers the onclick event handler _before_ executing the default action. This should be the case but I have not verified.
>
>> * Re-render teh component itself (which is what I did before: I just had an empty callback and the component would re-render itself based on state that was changed in the ajax callback)
> Right, this is because an actual submit happened before you included the 'return false' ?
> But if you want to re-render the entire component, why bother using ajax?
>
> Sorry if I misinterpret your intentions. I'm happy to help out but I'm puzzled by what you are trying to do ;-)
>
> best
> Johan_______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>



More information about the seaside mailing list