jquery加载解析XML文件

xml文件

<?xml version="1.0" encoding="utf-8" ?>
 <taxrates>
  <taxrate id="1">
    <lower>0</lower>
    <upper>500</upper>
    <rate>5</rate>
    <buckle>0</buckle>
  </taxrate>
  <taxrate id="2">
    <lower>500</lower>
    <upper>2000</upper>
    <rate>10</rate>
    <buckle>25</buckle>
  </taxrate>
  <taxrate id="3">
    <lower>2000</lower>
    <upper>5000</upper>
    <rate>15</rate>
    <buckle>125</buckle>
  </taxrate>
  <taxrate id="4">
    <lower>5000</lower>
    <upper>20000</upper>
    <rate>20</rate>
    <buckle>375</buckle>
  </taxrate>
</taxrates>

jquery代码

function StandardTaxRate()
{
    $.ajax({
        url: "/Resource/salaryTaxRate.xml",
        dataType: 'xml',
        type: 'GET',
        timeout: 2000,
        error: function(xml)
        {
            alert("加载XML 文件出错!");
        },
        success: function(xml)
        {
            $(xml).find("taxrate").each(function(i)
            {
                var oid = $(this).attr("id");
                var lower = $(this).children("lower").text();
                var upper = $(this).children("upper").text();
                var rate = $(this).children("rate").text();
                var buckle = $(this).children("buckle").text();
                ///后续操作。。。
            });
        }
    });
}
记忆力下降,日常日志
原文地址:https://www.cnblogs.com/yushuo/p/4540964.html