Why did you add "playlist.length = 0;" statement in document onready function. I did not see any use of it. I hope if you remove this statement it will work.
Regards, Prajwala On Mon, Apr 27, 2009 at 4:19 AM, [email protected] < [email protected]> wrote: > I have tried this solution. The best I can get it to return is a 1 or > a 0 in terms of array length, when it should be returning 5-10, as the > script should be adding a sub array every time. I also can't seem to > interact with it anywhere else, I have no idea what's going on. This > is the newer code: > > var playlist = []; > function ajaxMenu(whatTab){ > // retrieve the xml playlist > $(document).ready(function(){ > playlist.length = 0; > var id = 0; > var title = ''; > // start menu > $("#layout_left_menu_float").empty(); > $("#layout_left_menu_float").append("<ul>"); > // load the xml and run a foreach loop > var xmlPlaylist = $.ajax({ > type: "GET", > url: srcUrl+"playlist.xml", > dataType: "xml", > success: function(xml){ > $(xml).find('tab').each(function(){ > findTab = > $(this).find('id').text(); > if(findTab != > whatTab){ > return true; > } > else { > var i = '0'; > > $(this).find('item').each(function(index){ > // > Grab all details > > title = $(this).find('title').text(); > type > = $(this).find('type').text(); > file > = $(this).find('file').text(); > qt = > $(this).find('qt').text(); > wmv > = $(this).find('wmv').text(); > > content = $(this).find('content').text(); > > thumbnail = $(this).find('thumbnail').text(); > > // > Establish playlist item and add link > var > list = [index,title,type,file,qt,wmv,content,thumbnail]; > > playlist = [list]; > > > $("#layout_left_menu_float").append(itemLink > (index,title,type)); > }); > return false; // > speed fix, ends once correct tab found > } > }); // end each > } > }); > // end menu > $("#layout_left_menu_float").append("</ul>"); > > }); // end document ready > } > > Any ideas? > > Best regards, > Robert May. > > > On Apr 24, 1:50 pm, "[email protected]" > <[email protected]> wrote: > > I'm currently trying to build an array from an Ajax request, creating > > a new object for each item in the query. Here's the code: > > > > function ajaxMenu(whatTab){ > > // retrieve the xml playlist > > $(document).ready(function(){ > > var id = 0; > > var title = ''; > > // start menu > > $("#layout_left_menu_float").empty(); > > $("#layout_left_menu_float").append("<ul>"); > > var playlist = new Array(); > > > > // load the xml and run a foreach loop > > $.ajax({ > > type: "GET", > > url: srcUrl+"playlist.xml", > > dataType: "xml", > > success: function(xml) { > > > $(xml).find('tab').each(function(){ > > findTab = > $(this).find('id').text(); > > if(findTab != > whatTab){ > > return > true; > > } > > else { > > var i = > '0'; > > > $(this).find('item').each(function(index){ > > > // Grab all details > > > title = $(this).find('title').text(); > > > type = $(this).find('type').text(); > > > file = $(this).find('file').text(); > > > qt = $(this).find('qt').text(); > > > wmv = $(this).find('wmv').text(); > > > content = $(this).find('content').text(); > > > thumbnail = $(this).find('thumbnail').text(); > > > > > // Establish playlist item and add link > > > playlist[index] = new Object(); > > > playlist[index]['id'] = index; > > > playlist[index]['title'] = title; > > > playlist[index]['type'] = type; > > > playlist[index]['file'] = file; > > > playlist[index]['qt'] = qt; > > > playlist[index]['wmv'] = wmv; > > > playlist[index]['content'] = content; > > > playlist[index]['thumbnail'] = thumbnail; > > > > > $("#layout_left_menu_float").append(itemLink > > (index,title,type)); > > }); > > return false; > // speed fix, ends once correct tab found > > } > > }); // end each > > } // end success > > }); // end $.ajax > > // end menu > > $("#layout_left_menu_float").append("</ul>"); > > }); // end document ready > > } > > > > This function builds a menu from the items in a playlist, but at the > > same time I want to store the data in a global array to be used at any > > time, until it is overwritten when a new menu is created. > > > > How would I go about this? > > Any help will be most appreciated! > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
