[Seaside] jQuery Ajax: do something before and after

Johan Brichau johan at inceptive.be
Sun Mar 24 12:57:58 UTC 2013

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 ;-)


More information about the seaside mailing list