Solved

jcarousel with ajax solution

Posted on 2011-09-07
8
317 Views
Last Modified: 2012-08-13
Hi,

I'm using jquery jcarousel to create a slide show, but when I set the start page it does not go to the specific page, the page is here the code being in the source, but will attach for clarity, in this case I have set the start page to page 2.

Unfortunatly it stays on page 1?

What am I doing wrong:

code:

<script type="text/javascript"> 
                var carousel1;
                function mycarousel_itemLoadCallback(carousel, state)
                {
                    // Check if the requested items already exist
                    if (carousel.has(carousel.first, carousel.last)) {
                        return;
                    }
 
                    jQuery.get(
                    '/jcd_dev/images/getjson',
                    {
                        first: carousel.first,
                        last: carousel.last
                    },
                    function(xml) {
                        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
                    },
                    'xml'
                );
 
 
 
 
                };
 
                function mycarousel_itemAddCallback(carousel, first, last, xml)
                {
                    // Set the size of the carousel
                    carousel.size(parseInt(jQuery('total', xml).text()));
                    jQuery('image', xml).each(function(i) {
                        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
                    });
 
                };
 
                /**
                 * Item html creation helper.
                 */
                function mycarousel_getItemHTML(url)
                {
                    return '<img src="' + url + '" width="800" height="600" alt="" />';
                };
 
                jQuery(document).ready(function() {
                    jQuery.getJSON('/jcd_dev/images/gettext', function(data) {
                        $('body').data('text',data);
                        items = $('body').data('text');
                        $('#footercontent .titlebold').text(items["1"]["title"]);
                        $('#footercontent .titlelight').text(items["1"]["subtitle"]);
                    });
                    jQuery('#mycarousel').jcarousel({
 
                        // Uncomment the following option if you want items
                        // which are outside the visible range to be removed
                        // from the DOM.
                        // Useful for carousels with MANY items.
 
                        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
                        itemLoadCallback: mycarousel_itemLoadCallback,
                        itemVisibleInCallback: {
                            //onBeforeAnimation: setvar,
                            onAfterAnimation: echofirst
                        },
                        scroll: 1,
                        visible: 1,
                        start:2
                    });
                    carousel1 = jQuery('#mycarousel').data('jcarousel');
                    //hide spider text
                    $('#contentwrapper p').hide()
 
                });
 
 
                function echofirst(){
                    items = $('body').data('text');
 
                    try{$('#footercontent .titlebold').text(items[carousel1['first']]["title"]);
                    }
                    catch (err){
                        // not found
                    }
                    try{$('#footercontent .titlelight').text(items[carousel1['first']]["subtitle"]);
                    } catch (err){
                        // not found
                    }
 
                }
 
            </script> 

Open in new window

0
Comment
Question by:darren-w-
8 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 36494887
The sample url you provide returns an error aparently not related.

Can you tell us if carousel page returns any javascript error? There is any javascript error on Bugzilla/Javascript error console?
0
 
LVL 13

Author Comment

by:darren-w-
ID: 36495039
no, not receiving any errors?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36495042
gettext return a json object
getjson don't return a json object?


<data><total>5</total><image>jcd/img/imagecache/800x600_t4.jpg</image><image>jcd/img/imagecache/800x600_t6.jpeg</image><image>jcd/img/imagecache/800x600_t5.jpg</image><image>jcd/img/imagecache/800x600_t3.jpg</image><image>jcd/img/imagecache/800x600_t2.jpg</image></data>

Open in new window

0
 
LVL 13

Author Comment

by:darren-w-
ID: 36495282
This is from the original example here http://sorgalla.com/projects/jcarousel/examples/dynamic_ajax_php.html its actually returning a xml file, though on the page it is receiving the images therefore its working as expected.

Darren
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36495720
On line 32, get rid of :
first+i

It should be:
carousel.add( i, mycarousel_getItemHTML(jQuery(this).text()));
0
 
LVL 13

Author Comment

by:darren-w-
ID: 36497916
Humm, done something and it seems to be workingknow, to see the effect in action go to the url and add the parameter ?slide=2 ie http://94.193.107.131/jcd_dev/?slide=5, strange?

Darren
0
 
LVL 82

Expert Comment

by:hielo
ID: 36497976
It is working because on your current code you no longer have:
                       carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
 (like you did in the original code).  Your current code no longer has "first" like I suggested.

Also, if you take a closer look at your current code, you have, when you have:
?slide=5 the code the browser gets is:
 start:5

likewise, when  you use:
?slide=3 the code the browser gets is:
 start:3
 
So the code is being generated dynamically.  Having said that, your original problem was solved by post ID:36495720.
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 36498356
Yes, that is the case, the code is being generated dynamicly in the background, I'm making the page seo friendly so need to have the user land on the correct page, thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now