【问题标题】:IE 11 weird issue with JSONJSON 的 IE 11 奇怪问题
【发布时间】:2015-07-21 18:04:48
【问题描述】:

由于某种原因,我的 JSON 响应中的一个字段在 IE 中未定义。当我在 chrome 中运行它时,它看起来很好。但在 IE 中,当我写入控制台时显示未定义。

这是我的代码

function getList() {
    var argument = new Object();
    argument.identifier = _settings.identifier;

    $.ajax({
        url: "/Vendor.aspx/GetList",
        data: JSON.stringify(argument),
        dataType: 'json',
        contentType: 'application/json',
        error: function (xhr) {
            console.log(xhr);
        },
        success: function (data) {
            addData(JSON.parse(data.d));
        },
        type: 'POST'
    });
}

function addData(data) {
    if (data === undefined || data === null || data.length == 0) {
        alert('No data to show');
        return;
    }

    //this.clearRows();
    for (var index = 0; index < data.length; index++) {
        var d = data[index];

        var row = '<tr>' +
                  '<td>' + d.Item + '</td>' +
                  '<td>' + d.AlternativeItem + '</td>' +
                  '<td>' + d.Condition + '</td>' +
                  '<td>' + d.PCS + '</td>' +
                  '<td>' + d.Description + '</td>' +
                  '<td><input type="text" class="input-field-integer" id="' + d.Item + '"/></td>' +
                  '<td><input type="text" class="input-field-integer" value="' + d.Price + '"/></td>' +  //This field is empty in IE but not in Chrome.
                  '<td><input type="text" class="input-field" value="' + d.Condition2 + '"</></td>' +
                  '<td><input type="text" class="input-field" value="' + d.Stock + '"</></td>' +
                  '<td><input type="text" class="input-field" value="' + d.ETAIfNotInStock + '"</></td>' +
                  '</tr>';
        $(this._settings.fileTable + ' tbody').append(row);

        console.log(d.Price); // value is undefined???
    }

}

这是 JSON 的输出: {"Item":"1234","AlternativeItem":"","Condition":"新零售","PCS":"20","Description":"我的物品详情", "Price":"100","Condition2":"new","Stock":"5 stk.","ETAIfNotInStock":"","Comment":"","RowReference":null}

【问题讨论】:

  • 请包含您收到的 JSON(编辑为简短)
  • 您也可以尝试清除浏览器缓存。
  • 你的回复真的是双json编码的吗?
  • doule-json 编码是什么意思?
  • 成功处理程序中的data 是什么样的?

标签: javascript jquery asp.net json


【解决方案1】:

IE 可能正在缓存来自服务器的响应。

尝试将[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] 添加到来自服务器#WebAPI 的响应中

【讨论】:

    【解决方案2】:

    我已清除浏览器缓存,然后它开始工作。我必须清除它两次,然后重新启动计算机。

    IE 很特别。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-10
      • 2010-10-02
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多