Google 关闭 IE 中的 XhrIo 问题

发布于 2024-11-17 09:26:24 字数 2033 浏览 2 评论 0原文

以下代码在 IE 中不起作用,在我添加 try 块后,它会警告 Error: Could not Complete the opera due to error c00ce56e.

goog.require("goog.dom");
goog.require("goog.net.XhrIo");
goog.require("goog.structs.Map");
goog.require("goog.Uri.QueryData");

var errorMessage = "بروز خطا! بازیابی اخبار در این لحظه امکانپذیر نیست.";

loadPersepolisNews = function() {
  var url = 'EsteghlalNews?json=1'; 

  var request = new goog.net.XhrIo();
  goog.events.listen(request, "complete", function() {
    var container = goog.dom.$("persepolisNewsContainer");
    if (container != null && container != undefined) {        
      if (request.isSuccess()) {
        try {                  
          var json = request.getResponseJson();                            
        } catch (e) {
          alert(e);          
        }

        for (var i = 0; i < json.length; ++i) {
          var news = json[i];          
          var divNews = goog.dom.createDom('div', {
            'class': i % 2 == 0 ? 'news newsEven' : 'news newsOdd'
          });

          var newsLink = goog.dom.createDom("a", {
            'href': news.url, 
            'target': '_blank', 
            'class': 'newsLink'
          }, news.title);

          var newsDate = goog.dom.createDom("span", {
            'class': 'newsDate',
            'dir': 'ltr'
          }, news.persianDate.year + '/' + news.persianDate.month + '/' + news.persianDate.day);

          goog.dom.appendChild(divNews, newsLink);
          goog.dom.appendChild(divNews, newsDate);

          goog.dom.appendChild(container, divNews);
        }
      } else {
        alert(request.getStatusText());
        var message = goog.dom.createDom('div', {
          'style': 'background-color: red; color: white; padding: 2px'
        }, errorMessage);            
        goog.dom.appendChild(container, message);  
        console.log(request.getLastErrorCode(), " - message: ", request.getLastError());
      }
    }
  });

  request.send(url, "GET");
}

The following code doesn't work in IE, after I added the try block, it alerts Error: Could not complete the operation due to error c00ce56e..

goog.require("goog.dom");
goog.require("goog.net.XhrIo");
goog.require("goog.structs.Map");
goog.require("goog.Uri.QueryData");

var errorMessage = "بروز خطا! بازیابی اخبار در این لحظه امکانپذیر نیست.";

loadPersepolisNews = function() {
  var url = 'EsteghlalNews?json=1'; 

  var request = new goog.net.XhrIo();
  goog.events.listen(request, "complete", function() {
    var container = goog.dom.$("persepolisNewsContainer");
    if (container != null && container != undefined) {        
      if (request.isSuccess()) {
        try {                  
          var json = request.getResponseJson();                            
        } catch (e) {
          alert(e);          
        }

        for (var i = 0; i < json.length; ++i) {
          var news = json[i];          
          var divNews = goog.dom.createDom('div', {
            'class': i % 2 == 0 ? 'news newsEven' : 'news newsOdd'
          });

          var newsLink = goog.dom.createDom("a", {
            'href': news.url, 
            'target': '_blank', 
            'class': 'newsLink'
          }, news.title);

          var newsDate = goog.dom.createDom("span", {
            'class': 'newsDate',
            'dir': 'ltr'
          }, news.persianDate.year + '/' + news.persianDate.month + '/' + news.persianDate.day);

          goog.dom.appendChild(divNews, newsLink);
          goog.dom.appendChild(divNews, newsDate);

          goog.dom.appendChild(container, divNews);
        }
      } else {
        alert(request.getStatusText());
        var message = goog.dom.createDom('div', {
          'style': 'background-color: red; color: white; padding: 2px'
        }, errorMessage);            
        goog.dom.appendChild(container, message);  
        console.log(request.getLastErrorCode(), " - message: ", request.getLastError());
      }
    }
  });

  request.send(url, "GET");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞觅青森が 2024-11-24 09:26:24

问题出在服务器端(servlet)代码中。
IE 对 charset 值非常敏感。

正确的是:

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

但我是这样写的:(错误

response.setContentType("application/json");
response.setCharacterEncoding("UTF8");

The problem was in the serverside (servlet) code.
IE is very sensitive to the charset value.

The correct one is:

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

But I had written it this way: (wrong)

response.setContentType("application/json");
response.setCharacterEncoding("UTF8");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文