How to get Xml data to dynamic list

224 Views Asked by At

test.xml

<Bock1>
  <No>123</No>
  <RoomNo>10</RoomNo>
  <UpdateTime>1230</UpdateTime>
</Block1>

run.js

$.ajax({
  type: "GET",
  url: test.xml,
  dataType: "xml",
  success: function (xml) {
  $(xml).find('Block1').each(function () {
    var updateTime = $(this).find("UpdateTime").text();
    var no= $(this).find("No").text();
    var roomNo = $(this).find("RoomNo").text();
    var status = no + '<br/>' + roomNo + '<br/>' + updateTime;
    });
 }
});

$('<div>')
  .attr({
  'data-role': 'collapsible', 'data-collapsed': 'false', 'data-mini': 'true'
  })
  .html('<h4>' + item_name + '</h4><p>' + status + '</p>')
  .appendTo(collapsibleset);
  }
});

I'm using this to generate collapsibleset with xml data, but status can't correctly fill into

<p> + status + </p>

status will get correctly inside ajax, but can't get to collapsibleset. I've tried to use global variable, but get same situation. How could I fill it in correctly?

I'm new to jquery & javaScript, Thanks for any answers!!!

1

There are 1 best solutions below

0
Matt On

jQuery.ajax() is expecting string for the URL value. Therefore your URL just needs wrapping in quotes.

Then your DOM reference of the $('< div >') is wrong. To reference an element in JQuery, you have several options, but the easiest is to give an element an id and then reference that (think CSS) $('div') would get all divs $('div#my_id') would get this particular element: