0

我有一个显示平均等待时间的 xml 文件。我需要使用 jquery 和 ajax(或其他技术,如果这是更好的解决方案)读取该文件并将其显示在 html 页面中。我需要从节点中提取数据。我还需要将这些数据转换为对读者更友好的格式。所以 0:06 将显示 6 分钟,而 1:06 将显示 1 小时 6 分钟。

您可以在此处查看 xml 文件。

我试过这段代码没有成功:

 $(document).ready(function(){
$.ajax({
    type: "GET",
    url: "http://www.citizensmemorial.com/Temp/edwaittimes.xml",
    dataType: "xml",
    success: function(xml) {
        $(xml).find('edWait').each(function(){
            var time = $(this).attr('AverageWait');

            $('+time+');

        });
    }
});
});
4

1 回答 1

0

可能您想要的是Patients从 XML 中获取:

$.ajax({
  type: "GET",
  url: "http://www.citizensmemorial.com/Temp/edwaittimes.xml",
  dataType: "xml",
  success: function(xml) {
    // xml is the xml document
    // Find all `Patients`
    var patients = xml.querySelectorAll('patients');

    // Cycle through them to do stuff
    $.each(patients, function(i, node) {
      var time = node.querySelector('WaitTime').textContent.trim();
      time = convertTime(time);
      // Where do you want this time?
      // ...
    });
  }
});

function convertTime(time) {
  // I'm sure you can figure this out...
}

那应该有帮助。

看在上帝的份上,打开你的 JS 控制台。它会告诉你什么有效,什么无效。F12 或 CTRL+SHIFT+J。它会告诉你:

未捕获的错误:语法错误,无法识别的表达式:+

于 2013-09-11T08:14:29.403 回答