代码之家  ›  专栏  ›  技术社区  ›  aviv

msxml XMLHTTP for large json对象在IE8上运行得非常慢,在Firefox上运行得也很好-为什么?

  •  1
  • aviv  · 技术社区  · 14 年前

    我正在Firefox和IE8中创建一个XMLHTTP对象,并传输大量数据(json)。在Firefox中,它在5秒内渲染,在IE8中,它需要30秒。

    有没有办法让IE8 XMLHTTP工作得更快?

    下面是创建XHR对象的代码:

    function createRequestObject2()
    {
    var http_request = false;
    if(window.XMLHttpRequest)
    { //: Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if(http_request.overrideMimeType)
        {
            //: set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
        }
    }
    else if(window.ActiveXObject)
    { //: IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        }
        catch (e)
        {
             try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) { }
        }
    }
    if(!http_request)
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
    
    return http_request;
    }
    

    下面是我如何使用XHR:

           http = createRequestObject2();
           http.open('GET', encodeURI(action), true);
                http.onreadystatechange = results;
                http.send(null);
                inwork = true;
                viewLoading();
    
                //: search results handling
                function results()
                {
                    /*console.log("do_search.results[ " +
                            'Results return ' + http.readyState
                         + " ]"
                    );*/
                    if(http.readyState != 4)
                        return;
    
                    inwork = false;
    
                    if(http.status != 200)
                    {
                        //setStatusLine(httpapplicant.statusText);
                        return;
                    }
    
                    //: evaluate
                    var data = eval('(' + http.responseText + ')');
    
                    //: add data to the table
                    applicant_list = new dogtable(data, table1_options, $$('dog_results'));
    
                    hideLoading();
                } //function results
    
    0 回复  |  直到 14 年前