Load xml file content into div using jquery

前端 未结 5 2176
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 16:50

How to load the xml file content to a div.

Here is my HTML in which I need to load XML content

5条回答
  •  粉色の甜心
    2020-12-05 17:14

    Try this:

    // Load the xml file using ajax 
    $.ajax({
        type: "GET",
        url: "something.xml",
        dataType: "xml",
        success: function (xml) {
    
            // Parse the xml file and get data
            var xmlDoc = $.parseXML(xml),
                $xml = $(xmlDoc);
            $xml.find('category[name="My t"] logo').each(function () {
                $("#news-container").append($(this).text() + "
    "); }); } });

    Reference: 1. jQuery.ajax() 2. parseXML()

提交回复
热议问题