-1

The issue is I cannot access this local Json file named as dummy and this is blocked in chrome as something cors issue.

const getTodos = (callback) => {
  const request = new XMLHttpRequest()

  request.addEventListener('readystatechange', () => {
    if (request.readyState === 4) {
      const data = request.responseText
      if (request.status === 200) {
        callback(undefined, JSON.parse(data))
      } else {
        callback('! Could Not Fetch', data)
      }
    }
  })

  request.open('GET', 'dummy.json')
  request.send()
}

console.log('1')

getTodos((err, data) => {
  if (err) {
    console.log(err)
  } else {
    console.log(data)
  }
})

console.log('2')
Nawab Ali
  • 176
  • 2
  • 7

1 Answers1

-1

I am using html and using js script in head and if I use http-server to run my simple html project on http://127.0.0.1:8081 it is not blocking, So maybe this is the solution. But I am not 100% that this is good.

Nawab Ali
  • 176
  • 2
  • 7