简体   繁体   中英

Shopify: link to xml in a js file

Hi I'm using Shopify and I have a js file that I'm loading into a page. The JS file references an xml file. Both the js and the xml file are in the assets folder.

How do I reference the XML file? Below is what I have tried but it does not work. This is the error I'm getting: "NetworkError: 404 Not Found - http://myurl.myshopify.com/pages/%7B%7B%20%27data.xml%27%20|%20asset_url%20%7D%7D "

 $(window).load(function() {
    $.ajax({
        url: '{{ "data.xml" | asset_url }}',
        dataType: "xml",
        success: parse,
        error: function() {
            alert("Error: Something wrong with XML");
            xmlDoc = undefined;
    }
});
});

This is what I normally use when I'm not using Shopify. The XML file is in a folder called "xml". This works

$(window).load(function() {
    $.ajax({
        url: 'xml/data.xml',
        dataType: "xml",
        success: parse,
        error: function() {
            alert("Error: Something wrong with XML");
            xmlDoc = undefined;
        }
    });
});

What you're doing when you use {{ "data.xml" | asset_url }} is utilizing Shopify's URL filters . The documentation on asset_url specifically can be found here . You're essentially telling it to look for data.xml in your assets folder. If data.xml is not in your assets folder, but rather in your theme folder, you'll need to remove that Shopify filter and replace it with a real link, either absolute or relative. I can't see the structure of your theme, so I can't provide a more exact answer than that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM