asp.net – JSON在IE7中未定义

前端之家收集整理的这篇文章主要介绍了asp.net – JSON在IE7中未定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
它在chrome,firefox和IE8中工作正常。但IE7出现错误。这是我的jquery onchange事件。
$('select#NationId').change(function () {
        var nationId = $(this).val();
        $.ajax({
            url: 'LoadAreas',type: 'POST',data: JSON.stringify({ nationId: nationId }),dataType: 'json',contentType: 'application/json',success: function (data) {
                $('select#AreaId').get(0).options.length = 0;
                $('select#AreaId').append('<option value="0">Select All</option>');
                $.each(data,function (val,Areas) {
                    $('select#AreaId').append('<option value="' + Areas.Id + '">' + Areas.Name + '</option>');
                });
            }
        });
    });

控制器

[HttpPost]
    public ActionResult LoadAreas(int nationId)
    {
        var _Areas = (from c in SessionHandler.CurrentContext.ChannelGroups
                      join cgt in SessionHandler.CurrentContext.ChannelGroupTypes on c.ChannelGroupTypeId equals cgt.ChannelGroupTypeId
                      where cgt.Name == "Area" && c.ParentChannelGroupId == nationId
                      select new AreaName() { Id = c.ChannelGroupId,Name = c.Name }).OrderBy(m => m.Name);

        if (_Areas == null)
            return Json(null);
        List<AreaName> managers = (List<AreaName>)_Areas.ToList();

        return Json(managers);
    }

解决方法

问题是 the JSON object is not available in IE 7.您将希望在您的页面上包含 JSON2.js IE IE, 8位用户
原文链接:https://www.f2er.com/aspnet/253825.html

猜你在找的asp.Net相关文章