I read a lot of posts about this issue, but can not find a solution.
Also have seen the addSlide examples for the jQuery cycle plugin.

I try to add slides to the cycle plugin with AJAX, one slide at a time
with the following code.

  function onBefore(curr, next, opts, fwd) {
    // on Before arguments:
    //  curr == DOM element for the slide that is currently being
displayed
    //  next == DOM element for the slide that is about to be
displayed
    //  opts == slideshow options
    //  fwd  == true if cycling forward, false if cycling backward


    //Slide html creation helper.
    function ddblockGetSlideHTML(slideImg) {
      return '<img src="' + slideImg + '" width="200" height="200"
alt=""/>';
    };

    opts.ajaxLoadSlides = 1; // Will be set later from UI
    opts.totalSlideCount = 6; //Will be set later from UI
    //load slides dynamically
    if (opts.ajaxLoadSlides) {

      // on the first pass, addSlide is undefined (plugin hasn't yet
created the fn);
      // when we're finshed adding slides we'll null it out again
      if (!opts.addSlide){
        return;
      }

      if (opts.nextSlide + 1 == opts.totalSlideCount) {
        // final slide in our slide slideshow is about to be displayed
        // so there are no more to fetch
        alert('last slide to be dislayed, nothing to add anymore');
        opts.addSlide = null;
        return;
      }

      // Retrieve slide from server via AJAX, call; if successful the
      // anonymous function in voteSaved is run.
      $.ajax({
        type: 'POST', // Use the POST method.
        url: 'get_image_slides',
        dataType: 'json',
        data:
{js:true,origin:'ddblock',curr_slide:opts.currSlide,next_slide:opts.nextSlide,delta:opts.ddblocknr},
        success: function(data) {
          // add our next slide
          opts.addSlide(ddblockGetSlideHTML(data.slideImg), fwd ==
true);
        },
        error: function(xhr) {
          //alert('Error: ' + xhr.status + ' ' + xhr.statusText);
        }
      });
    }
  }

I first have 2 initial images
after that, images are loaded with AJAX
The ajax call returns the image ok
The problem is that opts.currSlide and opts.Nextslide give strange
values so the wrong images are selected.
When I look in FF console the post values for currSlide and nextSlide
are.

0 - 1
2 - 1
2 - 3
4 - 1
2 - 3
4 - 5

I get the images in the PHP script on nextSlide +2
So i expect :
0 - 1 -> get image 3
1 - 2 -> get image 4
2 - 3 -> get image 5
3 - 4 -> get image 6

Another problem is I use slideExpr to select the right content to
slide.
How can I you use addslide to add slides to the SlideExpr.parent

Thanks in advance for any help with this issue

Philip Blaauw

Reply via email to