码迷,mamicode.com
首页 > Web开发 > 详细

使用jq的ajax实现对xml文件的读取

时间:2018-04-03 14:30:09      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:from   3.1.1   XML   char   encoding   text   inf   set   教程   

之前一直在用json来传递数据,但是xml也是不可缺少的,于是开始了xml的征程。xml的一些属性啊之类的在菜鸟教程上列举的已经很详细了,但是却没有前段部分的获取教程,查询资料,遂懂:

index.xml:

<?xml version="1.0" encoding="UTF-8"?>
<note>
    <to>fangMing</to>
    <from>Tom</from>
    <heading>head</heading>
    <body>
        this is body
    </body>
</note>

  index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>

</body>
<script>
    $(() => {
        $.ajax({
            method: "GET",
            url: "index.xml",
            dataType: "xml",
            success: (xmlDoc, textStatus) => {
                textStatus === "success"&&(console.log($(xmlDoc).find("to").text()));

            }
        })
    })
</script>
</html>

  结果:技术分享图片

 

使用jq的ajax实现对xml文件的读取

标签:from   3.1.1   XML   char   encoding   text   inf   set   教程   

原文地址:https://www.cnblogs.com/mmykdbc/p/8707635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!