Jquery JSON and XML Simultaneous Load / Function Performance Improvement

mhm2010mhm

New Member
I have some jquery that is loading some information from an xml file to use as a Dictionary and then some json as well. I currently have the code working however It must currently wait for the xml load to be successful before loading the json. What I would like to do is load both the xml and json, store the data in variables and then when both have loaded fire off another function. Is this possible?Here is my current code...\[code\]$(document).ready(function () { var dict = {}; $.ajax({ type: "GET", url: "/_layouts/SiteLocations.xml", dataType: "xml", success: function (xml) { $(xml).find('type').each(function () { var key = $(this).find('key').text().replace(/ /g, '_'); var definition = $(this).find('definition').text(); //assign key and definition to dictionary dict[key] = definition; }); getsites(dict); } });});function getsites( dict) { $.getJSON('/_layouts/SiteLocations.ashx', function (json) { //handle data $.each(json, function (i, item) { //create web friendly id var sitetype = item.Type.replace(/ /g, '_'); //check if list exists, if not create if ($('ul[name=' + sitetype).length) { //add list item $('ul[name=' + sitetype).append('<li><a href="' + item.URL + '">' + item.Title + '</a></li>'); } else { //create list and add item $('#ListContainer').append('<div id="' + sitetype + '"></div>'); $('#' + sitetype).append(dict[sitetype] + '<br />'); $('#'+sitetype).append('<ul name="' + sitetype + '" />'); $('ul[name=' + sitetype).append('<li><a href="' + item.URL + '">' + item.Title + '</a></li>'); } }); });}\[/code\]
 
Back
Top