gpt4 book ai didi

Javascript 回调函数在 Firefox 中抛出错误 "Callback is not a function"

转载 作者:行者123 更新时间:2023-12-02 22:56:13 25 4
gpt4 key购买 nike

function CascadeDropDowns(parentClass, childClass, action, callback) {
var DropDownId = $(parentClass + " option:selected").val();

$.ajax({
url: "/site/" + action,
data: { DropDownId: DropDownId },
dataType: "json",
type: "POST",
error: function () {
alert("An error occurred.");
},
success: function (data) {
var items = "";
$.each(data, function (i, item) {
items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
});
$(childClass).html(items);
$(childClass)[0].selectedIndex = 0;
callback();
}
});
}

$(document).ready(function () {
// Populates all child drop downs on load
var callback = function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
};

CascadeDropDowns(".DeviceTypeDDL", ".ConfigGroupDDL", "GetGroups", callback);

// Populates all child drop downs parent change
$(".DeviceTypeDDL").change(function () {
var callback = function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
};
CascadeDropDowns(".DeviceTypeDDL", ".ConfigGroupDDL", "GetGroups", callback);
});
$(".ConfigGroupDDL").change(function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
});
});

这运行良好并以正确的顺序级联下拉菜单,但 Firefox 调试器显示错误,并且 ie 抛出警报并询问是否需要调试。

任何建议都会很好

最佳答案

这是因为您并不总是将回调传递给该方法。

success: function (data) {
var items = "";
$.each(data, function (i, item) {
items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
});
$(childClass).html(items);
$(childClass)[0].selectedIndex = 0;
if(callback) callback(); //check before calling it.
}

关于Javascript 回调函数在 Firefox 中抛出错误 "Callback is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com