在IE 8中没有更新的Knockout绑定

时间:2013-05-19 02:56:48

标签: jquery asp.net-mvc-4 knockout.js

我有一个显示数据库中项目列表的页面和一个用于添加新项目的文本框。当首次呈现页面时,列表在IE中正确显示,但是当我添加新项目时,列表不会在IE 8中更新。这在chrome中正常工作。这是我的代码:

self.ListOfDepartments.GetListOfAllDepartments = function () {
    $.getJSON('/Department/ListAllDepartments', function (data) {
        var mapped = ko.mapping.fromJS(data);
        self.ListOfDepartments(mapped);
    });
};

self.AddDepartmentModel.AddDepartment = function () {
    self.errors = ko.validation.group(this, { deep: true, observable: false });
    if (self.AddDepartmentModel.errors().length == 0) {
        $.ajax({
            url: "/Department/Add/",
            type: 'post',
            data: ko.toJSON(self.AddDepartmentModel),
            contentType: 'application/json',
            success: function (result) {
                $('#success').html('Department Added Successfully.');
                $("#success").dialog({
                    dialogClass: 'noclose',
                    autoOpen: true,
                    show: "blind",
                    hide: "explode",
                    modal: true,
                    open: function(event, ui) {
                        setTimeout(function() {
                            $('#success').dialog('close');
                        }, 3000);
                    }
                });
                Department.DepartmentName(null);
                Department.DepartmentName.isModified(false);
                self.ListOfDepartments.GetListOfAllDepartments();

            }
        });
    } else {
        self.AddDepartmentModel.errors.showAllMessages();
        return;
    }
};

HTML:

    <div data-bind="foreach: ListOfDepartments()">
        <div data-bind="text: DepartmentName" class="margin textStyle"></div>
    </div>

如果添加成功,则调用GetLIstOfAllDepartments时,我的页面列表不会在IE中更新。是否有一些特殊需要为IE做的事情?

1 个答案:

答案 0 :(得分:2)

找到解决方案。 IE正在缓存ajax请求,只需关闭缓存:

$.ajaxSetup({
    cache: false
});