?
Solved

jcarousel with ajax solution

Posted on 2011-09-07
8
Medium Priority
?
349 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 83

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 82

Accepted Solution

by:
hielo earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 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