Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Member #
    28626
    Can anyone tell me why this code is only getting the first node of the XML I am
    calling? Im trying to get Random images in the layers. Thanks in advance

    $(function loadXMLChannels() {
    $.ajax({
    type: "GET",
    url: "myFakeChannelData.xml",
    dataType: "xml",
    cache:false,
    success: changeChannel

    });
    });

    function changeChannel(xml) {
    $('#layer').fadeOut(1000);
    var $limit = 3;
    $("#click").click(function () {
    $(xml).find("Channel").each(function($limit) {
    var $channel = $(this);
    var image = $channel.attr('image');

    $("#layer-container").empty();
    $("#layer-container").append('<div class="layer1">' + '<img class=""
    alt="" src="' + image + '" />' + '</div></div>');
    $("#layer-container").append('<div class="layer2">' + '<img class="" alt=""
    src="' + image + '" />' + '</div></div>');
    $("#layer-container").append('<div class="layer3">' + '<img class="" alt=""
    src="' + image + '" />' + '</div></div>');
    $(".Channel").fadeIn(1000);
    });
    });
    var random = Math.floor($limit * Math.random());
    var myNewChannel = remix(random);
    myNewChannel(random);

    }

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    I don't get how you'd get random images into each layer. The line
    Code:
    $("#layer-container").empty();
    would remove any child elements from #layer-container, and therefore effectively only append elements to #layer-container the last time the loop was run.

    If you want a random image, what I would suggest you do is use the length property, something like this (although I haven't done this myself):
    Code:
    var channels = $(xml).find("Channel");
    var numChans = channels.length;
    var random = Math.floor (random * numChans);
    var image = channels[i].attr("image"); // I'm not sure if this syntax will work in jQuery, but if not, you can retrieve the child node as well with regular Javascript.
    The other thing you might have to do is output xml to a global variable so that it can be reused for different functions. Not sure in this particular case, though...I haven't done all that much with jQuery yet.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Member #
    28626
    Quote Originally Posted by TheGAME1264, post: 213214
    I don't get how you'd get random images into each layer. The line
    Code:
    $("#layer-container").empty();
    would remove any child elements from #layer-container, and therefore effectively only append elements to #layer-container the last time the loop was run.

    If you want a random image, what I would suggest you do is use the length property, something like this (although I haven't done this myself):
    Code:
    var channels = $(xml).find("Channel");
    var numChans = channels.length;
    var random = Math.floor (random * numChans);
    var image = channels[i].attr("image"); // I'm not sure if this syntax will work in jQuery, but if not, you can retrieve the child node as well with regular Javascript.
    The other thing you might have to do is output xml to a global variable so that it can be reused for different functions. Not sure in this particular case, though...I haven't done all that much with jQuery yet.
    Well thank you for replying. I definitely will try it....

  5. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Member #
    28626
    Quote Originally Posted by MartinsWebdev22, post: 213343
    Well thank you for replying. I definitely will try it....
    It hard to do OO programming with jQuery...

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    If it were easy, everyone could do it.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:42 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com