简体   繁体   English

多网络服务器 ajax 回调,在 Enter 上刷新

[英]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].关于如何发送带有 onSuccess 的 jQuery 回调的问题:当用户按下 [Enter] 时从 textInput 刷新。 We use the [Enter] press to trigger a search callback.我们使用 [Enter] 按下触发搜索回调。

Our GS Seaside app uses HAProxy.我们的 GS Seaside 应用程序使用 HAProxy。 This means the onSuccess: script is handled by a different gem than the one that handles the callback.这意味着 onSuccess: 脚本由不同于处理回调的 gem 处理。 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).正因为如此,用户有时会因为回调而获得刷新,在他们看来,这就像丢失的输入(浏览器 F5 刷新显示正确的状态)。 If running single gem or in a VW / Pharo image this problem does not come up.如果运行单个 gem 或在 VW / Pharo 图像中,则不会出现此问题。

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). ...但这使我无法显示任何等待反馈(我通常使用忙碌的 gif)。

So, the question is: in a multi-web server configuration, how can you code a callback to...所以,问题是:在多 Web 服务器配置中,你如何编写一个回调来......

1 - show a busy gif 1 - 显示一个忙碌的 gif

2 - trigger the search callback 2 - 触发搜索回调

3 - refresh the display when done 3 - 完成后刷新显示

...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.使用表单提交回调是一个问题,因为多个文本输入可以触发搜索,因为回调是“设置值 + 执行搜索”,默认按下 [Enter]。

For the JS callback, I'm using...对于 JS 回调,我正在使用...

    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'.由于'async:false',这一切都很好,除了缺少繁忙的gif。 Any suggestions?有什么建议么?

You can define a beforeSend and a complete handler to show and hide the loading indicator while the request is being processed.您可以定义一个beforeSend和一个complete的处理程序,以在处理请求时显示和隐藏加载指示器。 The global parameter set to false is meant to ignore your existing handlers to process request start and end (the mentioned spinner), and only use these defined in the particular instance of the JQAjax object.全局参数设置为false意味着忽略您现有的处理程序来处理请求开始和结束(提到的微调器),并且只使用在JQAjax object 的特定实例中定义的这些处理程序。


    ((html jQuery ajax)
        async: false;
        global: false; "https://api.jquery.com/category/ajax/global-ajax-event-handlers/"
        callback: aBlock value: canvas jQuery this value;
        onBeforeSend: (html jQuery id: 'indicator') show;
        onSuccess: ((html jQuery id: 'fieldId') load html: [:h | ]);
        onComplete: (html jQuery id: 'indicator') hide;

That said, keep in mind that doing a synchronous AJAX call is discouraged since it will block the whole UI thread until the request is resolved.也就是说,请记住,不鼓励执行同步 AJAX 调用,因为它会阻塞整个 UI 线程,直到请求得到解决。

So it's not completely clear how you manage the state in different worker images (gems, in this case) returning different things (probably because of having different sessions), so it's also not clear to me why doing an async XHR request will be served differently to doing it synchronously, I never experienced that.因此,尚不清楚您如何在不同的工作映像(在这种情况下为宝石)返回不同的东西(可能是因为有不同的会话)中管理 state,因此我也不清楚为什么执行异步 XHR 请求会以不同的方式提供服务同步进行,我从未经历过。

From the small sample you mention, it can't be deduced what is the "refresh" part of your code.从您提到的小样本中,无法推断出代码的“刷新”部分是什么。 So maybe, providing more context will help us give you more accurate answers.所以也许,提供更多上下文将有助于我们为您提供更准确的答案。

Fix ended up being trivial: needed to include 'event.preventDefault();'修复最终变得微不足道:需要包含 'event.preventDefault();' in the [Enter] key script.在 [Enter] 键脚本中。 Seems obvious in hindsight.事后看来很明显。

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

This problem is confirmed to be a narrow configuration symptom: GemStone with multiple gems.这个问题被确认是一个狭窄的配置症状:GemStone 有多个 gem。 On every other configuration Seaside / javascript behaves as expected.在所有其他配置 Seaside / javascript 的行为与预期相同。 I will follow this up as a vendor problem.我将将此作为供应商问题进行跟进。 Thanks to everyone that looked at it (this was also posted on other forums).感谢所有看过它的人(这也发布在其他论坛上)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM