Solved

jcarousel with ajax solution

Posted on 2011-09-07
8
334 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

696 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