Created by @Damo in Q&As
@Damo
@Damo

In a dynamic snippet iteration, I load external content, but the call is made only once. Is it a bug or do I have something wrong?

{foreach $windows as $window}
   ...
   <div id="snippet--x-window-content-{$window->id}">
      <p>Loading...{$window->id}</p>
   </div>
   ...
   <script>
      window._stack || (window._stack = []);
      window._stack.push(function(di) {
        di.getService('page').getSnippet("snippet--x-window-content-{$window->id}")
            .setup(function(elem) {
      // calls ajax only in the last iteration, why?
      di.getService('page').open({$window->modulePath}, 'GET', {"id" : {$window->id}}, { history: false });
      .teardown(function(elem) {
      });
   </script>
{/foreach}
@jahudka
@jahudka

Hi, that's most probably because normally page transactions can't run in parallel - a new transaction always aborts an existing transaction - so only the last one created will run normally, the rest will be aborted before the AJAX request is dispatched. You can avoid this by changing history: false to background: true (background transactions don't get pushed onto the browser history stack automatically).

@Damo
@Damo

Perfect, thanks

Sign in to post a reply