0

以下代碼在IE中無法正常工作,在我添加try塊後,它會提示Error: Could not complete the operation due to error c00ce56e.Google Closure XhrIo問題在IE中

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"); 
} 

回答

1

問題出在serverside(servlet)代碼中。
IE對charset值非常敏感。

正確之一是:

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

但我曾寫過這樣說:(錯誤

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