tags:

views:

46

answers:

3

I found this code but its not working... any suggestions the parsexml is never being called

$(document).ready(function(){
  $.ajax({
    type: "GET",
    url: "menuitems.xml",
    dataType: "xml",
    success: parseXml
  });
    // fourth example
    $("#black").treeview({
        persist: "location",
        collapsed: true
    });

});

var strMenu = "";
function parseXml(xml)

{
    alert();
  $(xml).find("Item").each(function()
  {
      if ($("#output").append($(this).attr("type") == "topic")) {
        strMenu += "<li><span>" + $("#output").append($(this).attr("name")) + "</span>";
      } else if ($("#output").append($(this).attr("type") == "link")) {
        strMenu += "<li><a href='" + $("#output").append($(this).attr("file")) + "'>" + $("#output").append($(this).attr("name")) + "</a></li>";
      }
  });
alert(strMenu); 
}
A: 

Try changing the line:

success: parseXml

to

success: parseXml(data)
Adam
A: 

does menuitems.xml exist? Is the path correct?

mdm20
menuitems.xml exists in two locations in the folder where the file that calls the js file is as well as the folder that the js file is in.
Erik
A: 

Changed

  $.ajax({
    type: "GET",
    url: "menuitems.xml",
    dataType: "xml",
    success: parseXml
  });

to

 $.ajax({ 
        type: "GET",
        url: "menuitems.xml",
        success: function(xml){
          parseXml(xml);
        }
      });

and now it works

Erik
Wow... it should have worked your original way. Sounds crazy, but it might if the function parseXml were declared above $(document).ready() -- just a thought.
harpo