0

I'm working with sportradar's API. However, I am getting this error "Uncaught SyntaxError: Unexpected token :" on the server response on line 1 in the schedule.json file when I run it. How do I resolve it to give me the data without using a plugin? You can see it in console.

function MLBSportsCall(){
  $.ajax({
    method: 'GET',
    url: `https://api.sportradar.us/mlb-t6/games/2016/07/21/schedule.json?api_key=ehnp54takzjxcgebm4uqrma9`,
    crossDomain: true,
    dataType: 'json',
    success: function(sportsData){
      console.log(sportsData)
    }
  })
}

https://repl.it/@rbirch/Sports-API

I have been going through the following resources. http://api.jquery.com/jquery.ajax/

JSONP request error handling

Thanks for your help.

Rob B.
  • 130
  • 1
  • 7
  • 24
  • and why do you think this is jsonp? – derloopkat Nov 25 '17 at 18:14
  • How would I know that it wasn't jsonp? It is json, not xml. I'm fairly new to ajax. I thought I should try jsonp as a datatype. – Rob B. Nov 25 '17 at 18:25
  • Because there is no call back function in this json. The error you're getting is CORS. – derloopkat Nov 25 '17 at 19:18
  • Isn't the success line a callback to do something with the data? – Rob B. Nov 25 '17 at 19:21
  • Ajax request doesn't come from same domain. https://www.maxcdn.com/one/visual-glossary/cors/ If the server wanted to allow people to use this api from outside they can do it by returning jsonp or adding allow cross origin header. It's their decision not yours. However there are tricks to by pass it. Someone else asked me same question here https://stackoverflow.com/questions/47301934/jquery-ajax-call-to-fetch-web-api-data-returns-syntax-error/47316607#47316607 – derloopkat Nov 25 '17 at 19:33

0 Answers0