如何将XML解析后的对象保存到JavaScript中

510 ℃
$.ajax({
  type: "GET",
  url: "books.xml",
  dataType: "xml",
  success: function(xml) {
    var xmlDoc = $.parseXML(xml),
      $xml = $(xmlDoc),
      books = [];
 
    $xml.find("book").each(function() {
      var book = {
        name: $(this).find("name").text(),
        author: $(this).find("author").text(),
        price: $(this).find("price").text()
      };
      books.push(book);
    });
    console.log(books);
  }
});

js如何将json对象转换成数组格式

标签: js数据转换, XML数据

上面是“如何将XML解析后的对象保存到JavaScript中”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_4198.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

wordpress无法调用the_content解决方法
js如何利用flatMap函数实现数组扁平化
es6如何从2个数组中找出相同项
thinkphp怎么转化时间戳(怎么删除多条数据)
php如何删除数组的空元素