Skip to content
Advertisement

javascript fetch api not working and giving error [closed]

i am using javascript to call a url. but is is giving me error in chrome console (F12)

please help me.

i expected a result

fetch(url).than((res) => {
  console.log(res.JSON())
})

but got an error instead

Advertisement

Answer

Its a typo. Simply use then instead of than and .json() instead of .JSON()

fetch(URL).then(res => {
  console.log(res.json())
})

learn more here

Advertisement