[英]getJSON is not a function when the second time I called it
這是我第一次使用jquery。 我在這里面臨的情況是我需要解析一些 JSON 文件,其 url 由另一個 JSON 文件給出。 因此,我使用代碼
var GlobalID = {};
function parseID() {
var data;
$.getJSON('https://taitk.org/api/algorithms', function(algorithms) {
GlobalID = algorithms;
console.log("ID got!");
parseKeyword();
});
}
function parseKeyword () {
for(var i = 0; i < GlobalID.length; i++) {
$.getJSON('https://taitk.org/api/algorithms/' + GlobalID[i].id, function(subdata) {
console.log(subdata.data)
});
}
}
,其中parseID()
是獲取每個 url 的 ID 的函數, parseKeyword()
是一個打印出每個 url 數據的函數(寫在回調函數中,從而避免異步函數調用)。
但是,我得到的錯誤是keyword.js:31 Uncaught TypeError: $.getJSON is not a function
而消息“ID got!” 打印成功。 此外,當我刪除parseKeyword()
函數時,代碼工作正常,這讓我感到困惑,因為第一個getJson()
調用似乎有效而第二個無效。
我想弄清楚我面臨什么樣的情況會導致這樣的錯誤,謝謝。
而且,下面是我如何在 html 文件中包含這些函數:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script></script>
<script src="js/keyword.js"></script>
<script type="text/javascript">
parseID()
</script>
真正的原因是我在<body>
部分中包含了 jquery 的精簡版本以及問題描述中提到的版本。 去掉之后,感覺還不錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.