SCRIPT5009:'String'未定义IE9

时间:2013-10-23 13:04:30

标签: jquery ajax internet-explorer-9 undefined

我使用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'未定义

我如何解决这个问题?

修改

此脚本可以正常运行:

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

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

1 个答案:

答案 0 :(得分: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;
    });
});