Solved

jcarousel with ajax solution

Posted on 2011-09-07
8
327 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular won't showing my array result in HTML 3 27
storing csv file in table variable in Python 2 27
Renaming with batch file 9 50
Search Item in Table 2 23
This article discusses four methods for overlaying images in a container on a web page
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

829 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