使用Jquery读取XML

时间:2012-03-28 10:13:52

标签: javascript jquery xml json

我的XML Feed看起来像这样

http://tinyurl.com/6wc6fel

不确定如何使用JQuery读取数据并以HTML格式显示?

我尝试在Google上搜索但没有找到很好的结果,因为您可以在我的XML中看到有很多元素

2 个答案:

答案 0 :(得分:1)

您是否有特殊原因需要在JSON中转换它?你可以先解析你检索的xml数据,然后用JSON.stringify

创建json。

以下是如何检索xml,您可以使用$ .ajax或$ .get方法:

<script type="text/javascript">
    $(document).ready(function () {

//YOU CAN USE THIS

        $.get("yourfile.xml", function (data) {            
            alert('Load was performed.');
        });

//OR THIS

        $.ajax({
            type: "GET",
            url: "yourfile.xml",
            dataType: "xml",
            success: function (xml) {
                alert('Load was performed.');
            }
        });

    });

 </script>

答案 1 :(得分:0)

您可以使用JParse插件

http://jparse.kylerush.net/demo