我在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