AltBrian
AltBrian

Reputation: 2572

Uncaught SyntaxError: Unexpected identifier on AJAX call back function

I am trying to access query an API and I am getting an Uncaught SyntaxError: Unexpected identifier on the success part of the JQuery Ajax function.

$(document).ready(function(){
$('#submitYear').click(function(){
let year = $("#year").val();
if(year != ''){
  //Get the Ajax request
  $.ajax({
    url:"http://ergast.com/api/f1/" + year + "/circuits.json?callback=myParser",
    type: "GET",
    dataType: "json"
    success: function(data){
      let widget = show(data);

      $("#show").html(widget);

      $("#year").val('');
    }
  });
}else {
  $("#error").html('Field cannot be empty');
}

});

 });

function show(data) {
let circuitHtml = '<ul>';
$.each(data.Circuits, function(i, place){
  circuitHtml += '<li> name: '+ place.circuitName + '</li>';

});
}

Upvotes: 0

Views: 996

Answers (1)

Beri
Beri

Reputation: 11620

You are missing a comma:

dataType: "json", <--here
success: function(data){

Upvotes: 2

Related Questions