Cors error when hitting specific parts of API

Hey guys, I’m getting a cors error when I hit a dog api asking for any specific breed. Here’s theDog API documentation. I am fine when I hit it not asking for any breed in particular. This is the jQuery code I’m using to hit the API:

$(document).ready(function() {
  function getDog() {
    let url = `https://dog.ceo/api/breeds/image/random`
    let breed = $('#breed').val().trim();
    if (breed !== 'select one') {
      url = `https://dog.ceo/api/breeds/${breed}/images/random`
    }
    $.ajax({
      url: url,
      type: 'GET',
      success: data => {
        $('#dogPic').html(`<img src="${data.message}">`)
        console.log(data)
      },
      error: err => {
        console.log(err)
      }
    })
  }
  getDog()
  $('#doggo').click(function () {
    getDog()
  })
})

Any help is greatly appreciated.

You need to look carefully at the API documentation example url. You have a typo.

1 Like

I see that extra s. thanks for the help