我試圖從Movie DB API檢索信息,jQuery代碼似乎沒有執行。我認爲我的JSON代碼可能關閉,但在重要功能之前測試之後,我意識到它並未運行。下面是該腳本:未在html中執行jquery腳本
<script type="text/javascript">
//test 0
$("#title").html('<h1>JS Loaded</h1>');
$(document).ready(function(){
//test 1
$("#title").html('<h1>Document Ready</h1>');
var getPoster = function(){
//test 2
$("#title").html('<h1>Get poster Executed</h1>');
$.getJSON(
"http://api.themoviedb.org/3/discover/movie?with_cast=31&sort_by=popularity.desc&api_key=d34d1c194fd655e99cc15a631bad6760&page=1",
function(data) {
if (data != "Nothing found."){
$('#poster').html('<img alt="Film/Show Poster" width="101px" height="150px" src=' + data.results[0].poster_path + ';>');
} else {
$('#title').html('<h1>NO POSTER WAS FOUND</h1>');
}
});
}
$('#poster').click(getPoster);
});
jQuery是在頭部聲明,就像這樣:
腳本SRC =「https://cdnjs.cloudflare.com/ajax/libs/jquery/ 3.2.1/jquery.min.js」完整性= 「SHA256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4 =」 crossorigin = 「匿名」>
任何瞭解到什麼問題可能是,將不勝感激。
對什麼是和什麼不工作更具體,也報告控制檯中拋出的任何錯誤(如果有的話)。花幾分鐘時間閱讀[問] – charlietfl
控制檯中是否有任何錯誤? –
是否收到任何錯誤?此外,您的IMG標記未正確關閉,請使用雙引號打開和關閉src。 – cosmoonot