Solved

jcarousel with ajax solution

Posted on 2011-09-07
8
321 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form with Modals 16 46
HTML Relative path 9 29
How to make interactive HTML code pages like w3school or Codecademy? 3 30
how to avoid redundand ajax calls 5 10
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

27 Experts available now in Live!

Get 1:1 Help Now