What's your biggest current challenge? Have your say in Community Polls along the right column.

How can I fetch JSON data in a '.liquid' file on a new platform?

How can I fetch JSON data in a '.liquid' file on a new platform?

jawadabbas
Tourist
6 0 1

Hey, i have recently hit a wall where I don't know how to fetch JSON data in Shopify, I'm new on the platform but I have experience in pure javascript. The following code is working on my own website ran by my server:

fetch ('/data.json')
    .then(response => response.json())
    .then(substance_data => {
      for (var substance in substance_data) {
        _substances_datalist.innerHTML += `<option value='${substance}'>`
      }
    })

But this does not work in a "section" .liquid file: {% javascript %}.

 

so my question is: how do I fetch JSON data I Shopify through .liquid file, and where do I put the JSON file.

Replies 0 (0)