当我第二次调用getJSON时,它不是一个函数

时间:2020-03-17 11:57:15

标签: javascript jquery

这是我第一次使用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的数据的函数(写在回调函数中,因此避免了异步函数调用)。 / p>

但是,我收到的错误是keyword.js:31 Uncaught TypeError: $.getJSON is not a function,而消息“ ID到了!”成功打印。另外,当我删除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>

1 个答案:

答案 0 :(得分:0)

真正的原因是,我在private void dtgTitulo_CellMouseUp(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex != 1) return; dtgTitulo.CommitEdit(DataGridViewDataErrorContexts.Commit); var contador = dtgTitulo.Rows.OfType<DataGridViewRow>().Count(r => (r.Cells[1].Value != null) && ((bool)r.Cells[1].Value == true)); if (contador <= 0) { btnUno.Enabled = false; btnVarios.Enabled = false; } else { if (contador == 1) { btnUno.Enabled = true; btnVarios.Enabled = false; } else { btnUno.Enabled = false; btnVarios.Enabled = true; } } } 部分中包含了jquery的精简版本以及问题描述中提到的版本。删除后,看起来不错。