【发布时间】:2019-07-03 19:04:26
【问题描述】:
使用 google chrome 编译时,函数的 else 语句中无法识别回调。尝试运行以下代码时,我的 site.js 文件出现错误:
function changeSetting(callback) {
var testswitch = document.getElementById("switch");
if (testswitch.checked) {
$.ajax({
type: 'GET',
url: '/api/ct/off/changeSetting',
cache: false,
error: function (jqXHR, textStatus, errorThrown) {
},
success: function (result) {
//No error here
callback();
}
});
}
else if (!testswitch.checked) {
$.ajax({
type: 'GET',
url: '/api/ct/on/changeSetting',
cache: false,
error: function (jqXHR, textStatus, errorThrown) {
},
success: function (result) {
//ERROR: Callback is not recognized as a function
callback();
}
});
} else {
return;
}
}
这个函数被调用的唯一实例是
changeSetting(displayEmail());
未捕获的类型错误:回调不是函数
【问题讨论】:
-
我想调用回调函数。删除 () 也不起作用。
标签: javascript ajax google-chrome callback