【发布时间】:2012-01-05 03:44:07
【问题描述】:
在一个网站上,我正在设计一个用户搜索城市中的酒店,结果以 xml 格式返回,然后通过 ajax/javascript/jquery 格式化。
结果在 Chrome 或 FF 中几乎立即显示,但在 Internet Explorer(我尝试过 ie6 和 ie9)中显示结果几乎需要一分钟。
在 IE 中运行开发人员工具表明 99% 的执行时间都花在了函数“getElementsByTagName”上,该函数被调用了近 200,000 次,但我不知道如果是这个问题该如何解决。
有问题的页面是beta.hotelsweep.com,搜索时调用的函数是:
//summarized version of the function
$.get(url, function (xmlResponse) {
$('#results').empty();
var exception = $("Exception", xmlResponse);
if (exception.size() > 0) {
var error = "<h2>We were unable to complete your request</h2>";
$('#results').html(error);
} else {
$('#numResults').html($("resultsNumber", xmlResponse).text() + " hotels found <br>");
var resultsHtml = "<div id='results_list'>";
//set googlem map to center
map.setCenter(new GLatLng($("avgLat", xmlResponse).text(), $("avgLong", xmlResponse).text()), 9);
// Loop through response, creating <li> for each hotel
$("Hotel", xmlResponse).each(function () {
var bookLink = $('affiliateLink', this).text();
var address = $('fulladdress', this).text();
var stars = $('stars', this).text();
resultsHtml += 'Hotel Stars: ' + stars;
});
//put html into results div
$('#results').html(resultsHtml);
}
});
【问题讨论】:
-
Chrome 使用的 javascript 引擎比 IE 快得多。
标签: javascript jquery ajax performance internet-explorer