Ajax功能无法在某些移动浏览器上显示xml数据

时间:2018-10-01 09:51:02

标签: javascript jquery ajax xml

我试图用html查看XML数据。该项目在桌​​面浏览器上可以正常运行,但在某些移动浏览器上则无法运行。我觉得问题很明显,但我不知道该怎么办。请帮忙。

<div class="row" id="xmldata"></div>
$(document).ready(function() {
  $.ajax({
    type: "GET",
    url: "data.xml",
    dataType: "xml",
    success: xmlParser2
  });
});

function xmlParser2(xml) {
  xml = $(xml).children();
  let total = $(xml).children().length;

  $(xml).children().each(function(idx, index, item) {
    let tag = $(this).prop("tagName");
    let nextIdx = idx + 1;
    let prevIdx = idx - 1;
    //to make cyclic
    nextIdx = nextIdx == total ? 0 : nextIdx;
    prevIdx = prevIdx == -1 ? (total - 1) : prevIdx;

    let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
    let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
    let head = '<div>' + $(this).find("head").text() + '</div>';
    let html = `<div class="col-sm-4 random reveal" id="random">
      <div class="thumbnail randomdiv3">
        <a href="#${tag + idx}" id="openModalBtn">
          <div>${image}</div>
          <h5>${head}</h5>
        </a>
      </div>
     </div>`;
    $("#xmldata").append(html);
  });
}

0 个答案:

没有答案