问题描述
背景信息
我正在制作一个通过AJAX调用从数据中获取数据的应用程序。如果成功方法满足要求,它将调用一个函数并将回调参数作为参数传递。然后在for循环中调用该回调。
问题
每当我调用回调函数时,它都会引发错误Uncaught TypeError:回调不是函数(在第39行)
我查找并尝试过的来源
首先让我说我已经对callback参数做了console.log()
并且值正确。
https://developer.mozilla.org/en-US/docs/Glossary/Callback_function
Uncaught TypeError: callback is not a function
add callback to function(e) Uncaught TypeError: callback is not a function
Uncaught TypeError: callback is not a function
我的代码
function Query(eventObject,button,callback)
{
//replaced not relevant code here with a comment.
success: function(response)
{
if (button === "getB")
{
//success fetches correctly. Already checked whether response Could be empty. This is not the case
response = JSON.parse(response);
if (callback)
{
//pass the callback along
rollOut(response,callback);
}
}
}
}
//THE FUNCTION I AM TRYING TO INVOKE
function setCheckBoxes(valuetoCompare)
{
console.log(valuetoCompare);
}
function rollOut(jsonResponse,callback)
{
$(`.show-divSet`).on(`click`,function () {
for (let i = 0; i < jsonResponse.length; i++)
{
if (jsonResponse[i]["version"] !== "")
{
//CONSOLE SHOWS ME THE CORRECT VALUE
console.log(callback);
//THIS IS LINE 39. THIS IS WHERE THE ERROR IS THROWN
callback(jsonResponse[i]["version"]);
}
}
});
}
我如何全部实例化代码
$(function () {
// I have already tried setCheckBoxes WITHOUT quotes,but unfortunately this didn't work either
Query("","getB","setCheckBoxes");
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)