-1

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!!!

Ann Yang
  • 11
  • 5
  • Possible duplicate of [jquery - How to get xml data](https://stackoverflow.com/questions/10811511/jquery-how-to-get-xml-data) – Kasia Gogolek Mar 23 '18 at 08:44
  • I've seen that question, but can't find solution, it seems generate list in ajax, but i need to get value inside ajax and fill it in list outside ajax. anyway ,thanks for reminding! – Ann Yang Mar 23 '18 at 09:14

1 Answers1

1

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:

Matt
  • 124
  • 12