0

我使用 jquery-1.7.2.min.js

我有以下 javascript:

$(function() {
    $("#del_category").click(function() {
        if (confirm('Are you sure you want to delete this category?')) {
            $.ajax({
                type: "POST",
                url: "someurl",
                datatype: "json",
                csd: window.parent.CSD,
                success: function(data) {
                    if (data.isSuccess) {
                        if (data.isFree) {
                            // error appears if this function invokes
                            this.csd.Popup.currentWindow.hideDialog();
                        } else {
                            alert("Category uses in some FAQ.");
                        }
                    } else {
                        alert("Error. Category was not deleted.");
                    }
                }
            });
        }

        return false;
    });
});

它适用于除 IE9 以外的所有浏览器。在 IE9 中它可以正常工作(调用所有函数)但显示 js 错误:SCRIPT5009: 'String' is undefined

我该如何解决这个问题?

编辑

此脚本可以正常工作:

$(function() {
    $("#del_category").click(function() {
        window.parent.CSD.Popup.currentWindow.hideDialog();
    });
});

错误仅出现在 ajax OnSuccess 事件处理程序中。

4

1 回答 1

0

试着把hideDialog();里面放一个setTimeout. 我相信错误即将出现,因为对话框在 jQuery 完成之前已被处理。

$(function() {
    $("#del_category").click(function() {
        if (confirm('Are you sure you want to delete this category?')) {
            $.ajax({
                type: "POST",
                url: "someurl",
                datatype: "json",
                csd: window.parent.CSD,
                success: function(data) {
                    if (data.isSuccess) {
                        if (data.isFree) {
                            // error appears if this function invokes
                            var csd = this.csd;
                            setTimeout(function() {
                                csd.Popup.currentWindow.hideDialog();
                            }, 0);
                        } else {
                            alert("Category uses in some FAQ.");
                        }
                    } else {
                        alert("Error. Category was not deleted.");
                    }
                }
            });
        }

        return false;
    });
});
于 2013-11-25T16:14:40.997 回答