我的作业是在此代码中查找错误,我不知道它是什么。我认为该错误位于此代码的JS部分中。有人可以帮忙吗?谢谢。 这是代码: https://codepen.io/DragonG/pen/gNmQgM
这是代码的JS部分:
/*
CHALLENGE: Fix the bug! The app is not responding to searches.
*/
const API_KEY = '5d576382955ff5829fc3844390db4427';
// When I click the button with an id of "searchForFilm", call the "findMovies" function.
$(function () {
$('#findThatFilm').click(findMovies);
})
function findMovies() {
// Read the text from an HTML element with an id of "userInput"
var inputString = $('#userInput').val();
// Make a call to the OMDB API with the search String we collected from the user input.
loadDataFromAPI(inputString);
}
function loadDataFromAPI(searchString) {
// Form an HTTP API request String that includes the desired searchString in the url.
var requestString = `https://api.themoviedb.org/3/search/movie?api_key=${API_KEY}&language=en-US&query=${searchString}`;
// Make the API request.
//
// When a result comes back, pass the data into the
// processAPIResult function
$.getJSON(requestString, processAPIResults);
}
function processAPIResults(data) {
var poster_base_url = "https://image.tmdb.org/t/p/w500";
if (data && data.results.length > 0) {
var firstResult = data.results[0];
$('.results').fadeIn(2000);
$('#title').html(firstResult.title);
$('#poster').attr("src", poster_base_url + firstResult.poster_path);
$('#releasedate').html("Released on 1/1/2000");
$('#synopsis').html(firstResult.overview);
$('#starring').html("");
} else {
$('#title').html("Sorry, we weren't able to find the film you were looking for. Maybe you made a mistake?");
$('#releaseyear').html("");
$('#starring').html("");
$('#synopsis').html("");
}
}