smalltalkseasidegemstone

Multi-web server ajax callback with refresh on Enter


Question about how to send a jQuery callback with an onSuccess: refresh from a textInput when the user presses [Enter]. We use the [Enter] press to trigger a search callback.

Our GS Seaside app uses HAProxy. This means the onSuccess: script is handled by a different gem than the one that handles the callback. Because of this, users will sometimes get the refresh because the callback, which to them looks like a lost input (a browser F5 refresh shows the right state). If running single gem or in a VW / Pharo image this problem does not come up.

I can work around the problem by using...

async: false;

...but that prevents me from show any kind of waiting feedback (I normally use a busy gif).

So, the question is: in a multi-web server configuration, how can you code a callback to...

1 - show a busy gif

2 - trigger the search callback

3 - refresh the display when done

...all in that order.

Using a form submission callback is a problem because multiple text inputs can trigger the search, since the callback is 'set value + do search', by virtual of the default [Enter] press.

For the JS callback, I'm using...

    self onKeyPress: (
    (JSStream 
        on: '(window.event ? window.event.keyCode : event.which) == 13')
        then: (canvas jQuery ajax callback: aBlock value: canvas jQuery this value))

It all works fine, except for the missing busy gif, due to the 'async: false'. Any suggestions?


Solution

  • Fix ended up being trivial: needed to include 'event.preventDefault();' in the [Enter] key script. Seems obvious in hindsight.

    if ((window.event ? window.event.keyCode : event.which) == 13) {
                event.preventDefault();
            };'